Stopping a MATLAB loop after certain condition

4 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops 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