Stopping a MATLAB loop after certain condition

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

VBBV
VBBV il 29 Giu 2023
Modificato: VBBV il 29 Giu 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 Commenti
VBBV
VBBV il 29 Giu 2023
compare the values in the Rudder array as above
rangga
rangga il 29 Giu 2023
yup! i works with some modification
thanks mate!!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by