If statement with multiple conditions

138 visualizaciones (últimos 30 días)
Jacqueline Rigatto
Jacqueline Rigatto el 13 de Nov. de 2020
Comentada: Jacqueline Rigatto el 14 de Nov. de 2020
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

Respuestas (2)

Walter Roberson
Walter Roberson el 13 de Nov. de 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
  1 comentario
Jacqueline Rigatto
Jacqueline Rigatto el 14 de Nov. de 2020
Thank you very much Walter Roberson, it helped a lot

Iniciar sesión para comentar.


Alan Stevens
Alan Stevens el 13 de Nov. de 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.
  1 comentario
Jacqueline Rigatto
Jacqueline Rigatto el 14 de Nov. de 2020
Thank you very much Alan Stevens, it helped a lot

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by