필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by