필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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
meghannmarie
meghannmarie 2019년 10월 7일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

meghannmarie
meghannmarie 2019년 10월 7일
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)))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by