## Incompatible Sizes for ode45 Output Assignment

I am trying to propagate orbits for a class project, and I’d like each orbit that is solved for using ode45 to be properly labelled instead of seeing ‘data1’ through ‘data11’ in the legend for the plot3() graph. If I can solve for each orbit without overriding it in the while loop, then I can just plot3() for each orbit individually, that’s why I have the idea of using the counter j as an index for an additional dimension in the ode45 output matrix.

%% Maneuver Type 1: a-change to get aInSat to same altitude/r/a value as YH

% Do maneuvers assuming we use all available thrust

j = 1;

% need to keep track of a_t & V_IS for overshoot issue, and T for phasing

% and other stuff for project like how long it took

while (r_IS(j) < a_YH)

V_IS(j + 1) = V_IS(j) + dv;

a_t(j) = ((2/r_IS(j)) – (V_IS(j + 1)^2)/Mu)^-1;

T(j) = pi*a_t(j)^(3/2) / sqrt(Mu);

% In-Sat can either be at 0[deg] or 180, mod() considers this

if(mod(j,2) == 0)

r_N = A_pn([r_IS(j);0;0],O_IS,w_IS,i_IS);

V_N = A_pn([0;V_IS(j + 1);0],O_IS,w_IS,i_IS);

x_0 = [r_N;V_N];

else

r_N = A_pn([-r_IS(j);0;0],O_IS,w_IS,i_IS);

V_N = A_pn([0;-V_IS(j + 1);0],O_IS,w_IS,i_IS);

x_0 = [r_N;V_N];

end

[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)], x_0, opts);

r_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),1:3));

V_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),4:6));

if(r_IS(j + 1) < a_YH)

% plot only if InSat does NOT end up past yellowhammer

plot3(trans_Orbit(:,1),trans_Orbit(:,2),trans_Orbit(:,3),’g’,’Linewidth’,2);

end

j = j + 1;

end

Throws the following error:

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

Error in Project (line 74)

[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)],x_0,opts);

The thing is, this fails after j = 8 iterations. It properly assigns the outputs from ode45 considering an additional dimension, but not past a certain point, the reason for which I cannot understand.

Again, if I can save all of the orbits without overriding any, I can print them all at the same time to allow for a proper legend.I am trying to propagate orbits for a class project, and I’d like each orbit that is solved for using ode45 to be properly labelled instead of seeing ‘data1’ through ‘data11’ in the legend for the plot3() graph. If I can solve for each orbit without overriding it in the while loop, then I can just plot3() for each orbit individually, that’s why I have the idea of using the counter j as an index for an additional dimension in the ode45 output matrix.

%% Maneuver Type 1: a-change to get aInSat to same altitude/r/a value as YH

% Do maneuvers assuming we use all available thrust

j = 1;

% need to keep track of a_t & V_IS for overshoot issue, and T for phasing

% and other stuff for project like how long it took

while (r_IS(j) < a_YH)

V_IS(j + 1) = V_IS(j) + dv;

a_t(j) = ((2/r_IS(j)) – (V_IS(j + 1)^2)/Mu)^-1;

T(j) = pi*a_t(j)^(3/2) / sqrt(Mu);

% In-Sat can either be at 0[deg] or 180, mod() considers this

if(mod(j,2) == 0)

r_N = A_pn([r_IS(j);0;0],O_IS,w_IS,i_IS);

V_N = A_pn([0;V_IS(j + 1);0],O_IS,w_IS,i_IS);

x_0 = [r_N;V_N];

else

r_N = A_pn([-r_IS(j);0;0],O_IS,w_IS,i_IS);

V_N = A_pn([0;-V_IS(j + 1);0],O_IS,w_IS,i_IS);

x_0 = [r_N;V_N];

end

[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)], x_0, opts);

r_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),1:3));

V_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),4:6));

if(r_IS(j + 1) < a_YH)

% plot only if InSat does NOT end up past yellowhammer

plot3(trans_Orbit(:,1),trans_Orbit(:,2),trans_Orbit(:,3),’g’,’Linewidth’,2);

end

j = j + 1;

end

Throws the following error:

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

Error in Project (line 74)

[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)],x_0,opts);

The thing is, this fails after j = 8 iterations. It properly assigns the outputs from ode45 considering an additional dimension, but not past a certain point, the reason for which I cannot understand.

Again, if I can save all of the orbits without overriding any, I can print them all at the same time to allow for a proper legend. I am trying to propagate orbits for a class project, and I’d like each orbit that is solved for using ode45 to be properly labelled instead of seeing ‘data1’ through ‘data11’ in the legend for the plot3() graph. If I can solve for each orbit without overriding it in the while loop, then I can just plot3() for each orbit individually, that’s why I have the idea of using the counter j as an index for an additional dimension in the ode45 output matrix.

%% Maneuver Type 1: a-change to get aInSat to same altitude/r/a value as YH

% Do maneuvers assuming we use all available thrust

j = 1;

% need to keep track of a_t & V_IS for overshoot issue, and T for phasing

% and other stuff for project like how long it took

while (r_IS(j) < a_YH)

V_IS(j + 1) = V_IS(j) + dv;

a_t(j) = ((2/r_IS(j)) – (V_IS(j + 1)^2)/Mu)^-1;

T(j) = pi*a_t(j)^(3/2) / sqrt(Mu);

% In-Sat can either be at 0[deg] or 180, mod() considers this

if(mod(j,2) == 0)

r_N = A_pn([r_IS(j);0;0],O_IS,w_IS,i_IS);

V_N = A_pn([0;V_IS(j + 1);0],O_IS,w_IS,i_IS);

x_0 = [r_N;V_N];

else

r_N = A_pn([-r_IS(j);0;0],O_IS,w_IS,i_IS);

V_N = A_pn([0;-V_IS(j + 1);0],O_IS,w_IS,i_IS);

x_0 = [r_N;V_N];

end

[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)], x_0, opts);

r_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),1:3));

V_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),4:6));

if(r_IS(j + 1) < a_YH)

% plot only if InSat does NOT end up past yellowhammer

plot3(trans_Orbit(:,1),trans_Orbit(:,2),trans_Orbit(:,3),’g’,’Linewidth’,2);

end

j = j + 1;

end

Throws the following error:

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

Error in Project (line 74)

[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)],x_0,opts);

The thing is, this fails after j = 8 iterations. It properly assigns the outputs from ode45 considering an additional dimension, but not past a certain point, the reason for which I cannot understand.

Again, if I can save all of the orbits without overriding any, I can print them all at the same time to allow for a proper legend. ode45, indexing MATLAB Answers — New Questions