Division from different For loop

조회 수: 5 (최근 30일)
Sun Kyoo Choi
Sun Kyoo Choi 2020년 3월 9일
편집: Ameer Hamza 2020년 3월 10일
Hi all,
I was wondering if I could divide two arrays or matrix from distinct for loop with a correct dimension.
For example,
gamma = 1.4;
R = 287;
p1 = [6.78,2.79,9.8,11.93,7.81,8.83,5.81,7.84,5.29,4.83,9.77];
T1 = [23,23,22.5,23,22,22,22,22.5,24.5,22.5,24];
for K = 1:length(p1)
p4 = 29.85;
fun = @(p2) p2/p4*(1 -((gamma-1)*(p2/p1(K)-1))./(2*gamma*(2*gamma+(gamma+1)*(p2/p1(K)-1))).^.5).^(-2.*gamma./(gamma-1))-1;
result(K) = fzero(fun,10)/p1(K) ;
end
for i = 1:length(T1)
fun1 = @(T2) (result(K)*T1(i)/T2)*(((gamma+1)/(gamma-1))+result(K))/(1+(((gamma+1)/(gamma-1))*result(K)))-1;
Temp(i) = fzero(fun1,25);
end
for Q = 1:length(T1)
a(Q) = sqrt(gamma*R*T1(Q));
end
M_s = w_s(j)./a(Q); => % this is my final goal, M_s, that I would like to get at the end. Both a(Q) and w_s(j) are 1x11 so that
%it has to give me 1x11 matrix after a division. However, for some reason, it only gives me 1x1 matrix. Is there any way
%to get a proper answer with a proper dimension? Thank you:)

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 3월 10일
편집: Ameer Hamza 2020년 3월 10일
w_s and a are 1x11. Whereas you are dividing w_s(j) and a(Q) which are 1x1. Use
M_s = w_s./a;

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by