If statement with multiple conditions
171 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
clear all; clc; close all
Tp=[4 7 11 16];
u= [0.188 0.368 0.628 0.997];
u10= [5.5 9.7 15 21];
ni_a=1.326*10^(-5);
sigma_p=2.*pi.*Tp.^(-1);
w2=((u.^2)./(ni_a.*sigma_p)).^(1.5);
r0=30:10:500;
SSGF = zeros(numel(Tp),numel(r0));
for Tp_Idx=1:length(Tp)
for r0_Idx=1:length(r0)
if Tp==4
if 30<=r0<75
SSGF=(7.84.*10.^(-3)).*r0.^(-1).*r0;
elseif 75<=r0<200
SSGF=4.41.*10.*(r0.^(-3)).*r0;
else
SSGF=(1.41.*10.^(13)).*r0.^(-8).*r0;
end
elseif Tp==7
if 30<=r0<75
SSGF=(7.84.*10.^(-3)).*r0.^(-1).*r0;
elseif 75<=r0<200
SSGF=4.41.*10.*(r0.^(-3)).*r0;
else
SSGF=(1.41.*10.^(13)).*r0.^(-8).*r0;
end
elseif Tp==11
if 30<=r0<75
SSGF=(7.84.*10.^(-3)).*r0.^(-1).*r0;
elseif 75<=r0<200
SSGF=4.41.*10.*(r0.^(-3)).*r0;
else
SSGF=(1.41.*10.^(13)).*r0.^(-8).*r0;
end
else
if 30<=r0<75
SSGF=(7.84.*10.^(-3)).*r0.^(-1).*r0;
elseif 75<=r0<200
SSGF=4.41.*10.*(r0.^(-3)).*r0;
else
SSGF=(1.41.*10.^(13)).*r0.^(-8).*r0;
end
end
end
end
Above is my code and my problem is that I am not able to make a matrix with 4 columns and 48 lines (SSGF). A piece of the table that was supposed to come out is in the image below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/413338/image.png)
Thanks in advance
0 Kommentare
Antworten (2)
Walter Roberson
am 13 Nov. 2020
if 30<=r0<75
means the same as
if ((30<=r0)<75)
The first part, 30<=r0, returns 0 (false) or 1 (true). Then you compare that 0 or 1 to 75.
You need to use &&
if 30 <= r0 && r0 < 75
Alan Stevens
am 13 Nov. 2020
Don't forget the indices:
if Tp(Tp_Idx)==4
if 30<=r0(r0_Idx)<75
SSGF(Tp_Idx,r0_idx)=(7.84.*10.^(-3)).*r0(ro_Idx).^(-1).*r0(r0_Idx);
...etc.
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!