1 view (last 30 days)

pi_c = [2 3 5 10 20 30];

M_0 = 0.1:0.1:3;

for i = 1:length(M_0)

tau_r = 1+(gamma-1)*M_0(i)^2/2;

for j = 1:length(pi_c)

tau_c = pi_c(j)^((gamma-1)/gamma);

tau_t = 1-(tau_r/tau_lambda)*(tau_c-1);

S_2 = c_p*T_0*g_c*(tau_lambda-tau_r*tau_c)./(a_0*h_PR*...

(sqrt(2*tau_lambda*(tau_r*tau_c*tau_t-1)/...

((gamma-1)*tau_r*tau_c))-M_0));

S_2_vec(i,j) = S_2*10^6;

end

end

When I run the program I get this error:

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

Error in HW4 (line 120)

S_2_vec(i,j) = S_2*10^6;

When I step through the program, the first time it calculates S_2, it instantly forms a 1x30 matrix, rather than just calculating one value for that iteration.

Any help would be greatly appreciated.

All the variables are shown below, the only 1x30 matrix is M_0

meghannmarie
on 7 Oct 2019

When you calculate S_2, M_0 is subtracted in last part of the equation making it a 1x30 matrix. Should you be subtracting M_0(i)?

S_2 = c_p* ...other stuff in calculation... - M_0(i)))

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/484054-why-is-this-matrix-instantly-forming-in-the-middle-of-the-for-loop#comment_753616

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/484054-why-is-this-matrix-instantly-forming-in-the-middle-of-the-for-loop#comment_753616

Sign in to comment.