Azzera filtri
Azzera filtri

How to use looping

3 visualizzazioni (ultimi 30 giorni)
Skydriver
Skydriver il 27 Nov 2019
Commentato: Skydriver il 2 Dic 2019
I have a coding like this:
for k=1:length(Depth)
if Depth(k)>0 & Depth(k)<=6
RdFk(k) = -0.0425 .*Depth(k)+1.0333
elseif Depth(k)>6 & Depth(k)<12
RdFk(k) = 0.0006 .*(Depth(k))^2 + 0.0048.*(Depth(k))+0.7865
elseif Depth(k)>=12 & Depth(k)<=15
RdFk(k) = -0.02.*Depth(k) + 1.06
else Depth(k)>16 & Depth(k)<=30
RdFk(k) = -0.0025.*(Depth(k))^2+0.072.*(Depth(k))+0.261
end
end
Why the coding only read the last else (last criteria i.e. RdFk(k) = -0.0025.*(Depth(k))^2+0.072.*(Depth(k))+0.261 ) and pass through other criteria?
Thx

Risposta accettata

David Hill
David Hill il 27 Nov 2019
You might want to eliminate your loop.
RdFk=zeros(size(Depth));
RdFk(Depth>0&Depth<=6) = -0.0425*Depth(Depth>0&Depth<=6)+1.0333;
RdFk(Depth>6&Depth<=12) = 0.0006*(Depth(Depth>6&Depth<=12)).^2 + 0.0048*(Depth(Depth>6&Depth<=12))+0.7865;
RdFk(Depth>12&Depth<=15) = -0.02*Depth(Depth>12&Depth<=15) + 1.06;
RdFk(Depth>15&Depth<=30) = -0.0025*(Depth(Depth>15&Depth<=30)).^2+0.072*(Depth(Depth>15&Depth<=30))+0.261;
  1 Commento
Skydriver
Skydriver il 2 Dic 2019
I change the zero with ones and it works now
Thank you

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by