Please help in convergence of the array

for l = 1:6
c11 (l)=opt11{l};
end
output = c11 =
Columns 1 through 5
89.0475 98.7932 98.7932 98.7932 98.7932
Column 6
98.7932
I want to break the loop "l" in program if c11(i+1)<=c11(i). please help me.

 Réponse acceptée

Guillaume
Guillaume le 4 Août 2016
Modifié(e) : Guillaume le 4 Août 2016
Well, you already nearly wrote the answer yourself!
for ...
... do something
if condition
break; %stop the loop
end
end
So, in your case, probably:
for l = 1:6
c11(l) = opt11{l}
if l>1 && c11(l) <= c11(l-1)
break;
end
end
Of course, the above could be just written without the loop:
c11 = cell2mat(opt11(1:6));
c11 = c11(logical(cumprod(diff(c11) > 0)));

3 commentaires

Triveni
Triveni le 4 Août 2016
Modifié(e) : Triveni le 4 Août 2016
Thanks sir, you have given me perfect answer which i want. Sir please help me once again, if i want, c11(l+1)<= or ==c11(l+4) continuously for three times, then i want to break or defined 1,2,3 or 4 then how can i break? or,
Columns 1 through 4
[93.6568] [98.9636] [93.4562] [103.8119]
Columns 5 through 8
[101.4730] [103.8119] [101.4730] [103.8119]
Columns 9 through 12
[101.4730] [103.8119] [101.4730] [103.8119]
Columns 13 through 16
[101.4730] [103.8119] [101.4730] [103.8119]
Columns 17 through 20
[101.4730] [103.8119] [101.4730] [103.8119]
%
%After column 4, I want to avoid this type of repetition.
Stephen23
Stephen23 le 4 Août 2016
@Triveni: it sounds like you are really trying achieve some task which you have not told us about. Rather than getting us to fix some broken code, it would be better if you actually described what you are trying to achieve:
Actually if i post whole code then you need to pay attention at-least for 5 to 10 minutes to analyze my code. My question is not so difficult, i have to stop only loop in different circumstances which i have told you.
[93.6568] [98.9636] [93.4562] [103.8119]
Columns 5 through 8
[101.4730] [103.8119]
In column 1, 2, 3, 4, and 5 value increase and then decrease, then value is continuously increase and decrease. If increase and decrease is steady then i have to break my loop. I have to find out maximum value from c11. When value is not maximizing and it's going steady then i need not to solve it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by