フィルターのクリア

If statement with multiple conditions

177 ビュー (過去 30 日間)
Jacqueline Rigatto
Jacqueline Rigatto 2020 年 11 月 13 日
コメント済み: Jacqueline Rigatto 2020 年 11 月 14 日
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.
Thanks in advance

回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 11 月 13 日
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
  1 件のコメント
Jacqueline Rigatto
Jacqueline Rigatto 2020 年 11 月 14 日
Thank you very much Walter Roberson, it helped a lot

サインインしてコメントする。


Alan Stevens
Alan Stevens 2020 年 11 月 13 日
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.
  1 件のコメント
Jacqueline Rigatto
Jacqueline Rigatto 2020 年 11 月 14 日
Thank you very much Alan Stevens, it helped a lot

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by