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

 채택된 답변

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

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개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2015년 7월 4일

편집:

2015년 7월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by