I am having trouble creating a loop for inputs into a function

조회 수: 1 (최근 30일)
Logan DiCerb
Logan DiCerb 2022년 7월 11일
댓글: Bharat Chandra Mukkavalli 2022년 7월 12일
I have a MATLAB code and function that finds values needed for a turbojet analysis and here is the function I created and I am calling for a project:
[ST,S,Thrust] = dualspoolturbofan(M_0,mdot_0,T_0,p_0,pi_dmax,T_t4,eff_b,pi_b,h_PR,alpha,pi_cL,pi_c,pi_f,gamma_c,cp_c,e_cL,e_cH,gamma_t,cp_t,e_tL,e_tH,e_f,eff_mH,eff_mL,pi_n,pi_fn,p0_p9,gc);
My problem statement is to then plot the outputs vs M_0 (3v1 graph), while M_0 changes from (0.0,0.9,30) (30 values between 0.0 & 0.9), and T_t4 changes from 2800,3200,3400 (just those 3 values)
So 90 total changed inputs with the 30 Mach values and 3 temperature values. I am just stuck on what loops to create to satisfy this problem statement. Thanks so much!!

답변 (1개)

Bharat Chandra Mukkavalli
Bharat Chandra Mukkavalli 2022년 7월 12일
Hi,
As I understand, you want to plot three graphs ST vs M_0, S vs M_0 and Thrust vs M_0 for different discrete values of T_t4.
You can run the following loops to achieve this:
M_0 = linspace(0, 0.9, 30);
titledlayout(3, 1);
for temp in [2800, 3200, 3400]
ST_vec = [];
S_vec = [];
Thrust_vec = [];
for m in M_0
[ST,S,Thrust] = dualspoolturbofan(m, ..., temp, ...);
ST_vec(end+1) = ST;
S_vec(end+1) = S;
Thrust_vec(end+1) = Thrust;
end
nexttile
hold on
plot(M_0, ST_vec);
plot(M_0, S_vec);
plot(M_0, Thrust_vec);
hold off
end
Hope this helps!
  댓글 수: 4
Rik
Rik 2022년 7월 12일
No, it does not. 'in' is not a valid Matlab syntax. You can easily check this by formatting your code as a code section, instead of an inserted example.
M_0 = linspace(0, 0.9, 30);
titledlayout(3, 1);
for temp in [2800 3200 3400]
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
ST_vec = [];
S_vec = [];
Thrust_vec = [];
for m in M_0
[ST,S,Thrust] = dualspoolturbofan(m, ..., temp, ...);
ST_vec(end+1) = ST;
S_vec(end+1) = S;
Thrust_vec(end+1) = Thrust;
end
nexttile
hold on
plot(M_0, ST_vec);
plot(M_0, S_vec);
plot(M_0, Thrust_vec);
hold off
end

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

카테고리

Help CenterFile Exchange에서 Cloud Integrations에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by