Modify the following program in order to get rid of the break statement without affecting the behavior of the program
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Taylie Sargent
le 4 Juil 2015
Modifié(e) : Geoff Hayes
le 4 Juil 2015
a = rand(1, 10);
index = 1;
while index <= size(a, 2)
if a(index) > .7
break
end;
a(index)
index = index + 1;
end;
0 commentaires
Réponse acceptée
Nobel Mondal
le 4 Juil 2015
Hi Taylie,
I am not sure why you want the 'break' to be removed. However, the following code works - but NOT an elegant way of doing it.
a = rand(1, 10);
index = 1;
while index <= size(a, 2)
if a(index) > .7
index = size(a,2) + 1;
else
a(index)
index = index + 1;
end
end
Thanks,
Nobel.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!