Stopping a MATLAB loop after certain condition

4 ビュー (過去 30 日間)
rangga
rangga 2023 年 6 月 29 日
コメント済み: rangga 2023 年 6 月 29 日
above is my plot of my ship heading(blue) and rudder angle(red), i'd like to stop my loop after the red line data have 4 value of 0 (or aprox. 0).
red line data is 2 row vector of array with double precision (in case you wonder).
i know it's a simple condition but i just don't know how to make the script.
could anyone tell or show me how to do it? i appreciate it.

採用された回答

VBBV
VBBV 2023 年 6 月 29 日
編集済み: VBBV 2023 年 6 月 29 日
Rudder = repmat([rand(1,5), 0, rand(1,5), 0, rand(1,5), 0, rand(1,5), 0],2,1)
Rudder = 2×24
0.9995 0.4196 0.6164 0.8721 0.6362 0 0.8652 0.3240 0.3273 0.1284 0.3913 0 0.2856 0.4808 0.7988 0.0282 0.3477 0 0.0671 0.2529 0.0200 0.2973 0.0620 0 0.9995 0.4196 0.6164 0.8721 0.6362 0 0.8652 0.3240 0.3273 0.1284 0.3913 0 0.2856 0.4808 0.7988 0.0282 0.3477 0 0.0671 0.2529 0.0200 0.2973 0.0620 0
count = 0;
for x = 1:size(Rudder,1)
for k = 1 : length(Rudder)
if Rudder(x,k) == 0
count = count + 1;
end
if count >= 4
break;
end
end
end
count
count = 4
  2 件のコメント
VBBV
VBBV 2023 年 6 月 29 日
compare the values in the Rudder array as above
rangga
rangga 2023 年 6 月 29 日
yup! i works with some modification
thanks mate!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by