Stopping a MATLAB loop after certain condition

4 Ansichten (letzte 30 Tage)
rangga
rangga am 29 Jun. 2023
Kommentiert: rangga am 29 Jun. 2023
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.

Akzeptierte Antwort

VBBV
VBBV am 29 Jun. 2023
Bearbeitet: VBBV am 29 Jun. 2023
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 Kommentare
VBBV
VBBV am 29 Jun. 2023
compare the values in the Rudder array as above
rangga
rangga am 29 Jun. 2023
yup! i works with some modification
thanks mate!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by