How to verify a while loop and run it correctly?

조회 수: 4 (최근 30일)
Amine Ben Ayara
Amine Ben Ayara 2016년 2월 25일
댓글: Amine Ben Ayara 2016년 2월 25일
Hello, I have written a code using a while loop. which basically uses 3 input matrices, two of which are identical in dimensions, suppose (10*3): MI1, and MI2. the third one is (10*100): MI3. The objective is to get a final matrix: M that is (n*3), the nbr of rows depends on the conditions that while loop has to check: My simulation is based on these steps: 1st row of the output matrix M is = to the the 1st row of MI1. then it compares MI1(2,3) to MI2(1,3), if MI1(2,3)>max(MI2(:,3:end) then M(2,:)=MI1(2,:), else M(2,:)=MI2(row(where the max is),:); then the max(MI2) selected already is replaced by a value from MI3, indexed at MI2((where the max is, 2))+1; and this will continue until the loop runs throw all the rows of MI1. I can provide my code and a very small data set if necessary. I hope my explanation is clear.
Thanks

답변 (1개)

Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 2월 25일
edit your question again and post code with error you are getting?
Only after my understanding i recommend you to use For loop rather than While loop which may run for infinity iritations
  댓글 수: 1
Amine Ben Ayara
Amine Ben Ayara 2016년 2월 25일
Muhammed, Thank you for your answer. I will make a very small numerical example and attach it to my edited question shortly.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by