Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to run various steps in loop with conditions?

조회 수: 1(최근 30일)
kitty varghese
kitty varghese 2017년 8월 31일
마감: MATLAB Answer Bot 2021년 8월 20일
i have a set of steps which i need to run until a given condition is satisfied. this should run until i get non negative matrix v. this program is a rough draft.This may or maynot give output,i just want to know how to set such conditions.
if true
v=[1 2 -5 7, 4 -8 6 77,-11 -84 25 47,36 -47 -88 99]; zerocoeff=find(v < 0); v(zerocoeff)=0; s=v./(-12); v=v+s
  댓글 수: 1
Jan
Jan 2017년 8월 31일
편집: Jan 2017년 8월 31일
@kitty: Do you know the "{} Code" button already? Your code is short in this question, and it can be read. But using the standard methods in the forum for formatting improves the readability. I had to think twice if the "if true" belongs to the code or is an artifact only.
What is the "condition" you are asking for?

답변(1개)

José-Luis
José-Luis 2017년 8월 31일
What's wrong with a while loop?
condition = True;
while condition
%do your thing
condition = something == some_other_thing; %Evaluate to false when you want to break
end

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by