Stopping a MATLAB loop after certain condition

4 vues (au cours des 30 derniers jours)
rangga
rangga le 29 Juin 2023
Commenté : rangga le 29 Juin 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.

Réponse acceptée

VBBV
VBBV le 29 Juin 2023
Modifié(e) : VBBV le 29 Juin 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 commentaires
VBBV
VBBV le 29 Juin 2023
compare the values in the Rudder array as above
rangga
rangga le 29 Juin 2023
yup! i works with some modification
thanks mate!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by