Effacer les filtres
Effacer les filtres

Why is this matrix instantly forming in the middle of the for loop?

3 vues (au cours des 30 derniers jours)
Joseph Zvonek
Joseph Zvonek le 7 Oct 2019
Commenté : Joseph Zvonek le 7 Oct 2019
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
matlab_pic.jpg
  1 commentaire
meghannmarie
meghannmarie le 7 Oct 2019
One of the variables used to calculate S_2 must be a matrix (probably a 1x30 matrix). You even use the dot operator for the division leading me to believe one of these is a matrix.
This is hard to troubleshoot without some sample data for all those unknown variables.

Connectez-vous pour commenter.

Réponse acceptée

meghannmarie
meghannmarie le 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)))

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by