フィルターのクリア

Modify the following program in order to get rid of the break statement without affecting the behavior of the program

1 回表示 (過去 30 日間)
a = rand(1, 10);
index = 1;
while index <= size(a, 2)
if a(index) > .7
break
end;
a(index)
index = index + 1;
end;

採用された回答

Nobel Mondal
Nobel Mondal 2015 年 7 月 4 日
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.
  1 件のコメント
Taylie Sargent
Taylie Sargent 2015 年 7 月 4 日
Hi Nobel,
Thank you for answering. I'm just starting to learn the ropes of matlab and this was one of the exercises questions, so not something I was actually working with in the program.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by