フィルターのクリア

How to use looping

3 ビュー (過去 30 日間)
Skydriver
Skydriver 2019 年 11 月 27 日
コメント済み: Skydriver 2019 年 12 月 2 日
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

採用された回答

David Hill
David Hill 2019 年 11 月 27 日
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 件のコメント
Skydriver
Skydriver 2019 年 12 月 2 日
I change the zero with ones and it works now
Thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by