How can I combine if statement inside for loop?
이전 댓글 표시
clc
clear all
t = [-0.095; -3.953; -7.52; 7.59; 37.66]
m6 = 1.4544e+06;
m5 = -5.7624e+05;
m4 = -1.8298e+08;
m3 = -6.3483e+08;
m2 = -1.0784e+08;
m1 = -8.3759e+07;
m0 = -7.4807e+06;
g5 = -1.8497e+06;
g4 = -7.9658e+06;
g3 = -1.5743e+07;
g2 = -3.0234e+06;
g1 = -2.0215e+06;
g0 = -1.7686e+05;
R22 = 0.4752;
for i=1:length(t)
ti=t(i)
X(i) = m0 + m1*ti + m2*ti^2 + m3*ti^3 + m4*ti^4 + m5*ti^5 + m6*ti^6;
Y(i) = g0 + g1*ti + g2*ti^2 + g3*ti^3 + g4*ti^4 + g5*ti^5;
Z(i) = X(i)/Y(i);
if Z(i) > 0
wc(i) = sqrt(R22/Z(i))
td(i) = (2/wc(i))*atan(wc(i)*ti);
else
return
end
td = min(td(j))
end
The for loop is intended to compute values of Z(i) as per corresponding values of t (i). Then, if the value of Z(i) is positive value, only then the values of wc(i) and td(i) going to be computed. For all possible values of td(i), the chosen value going to be the minimum of all.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!