필터 지우기
필터 지우기

Print out values in a while loop each time into an array.

조회 수: 1 (최근 30일)
JE
JE 2015년 10월 16일
댓글: Ken Atwell 2015년 10월 16일
I want this while loop to print out the endlocation each time into an array. How do I do this?
while startcounter<7088
while start{1,1}(startcounter)>stop{1,1}(endcounter);
endcounter=(endcounter)+1;
endlocation=stop{1,1}(endcounter);
end
startcounter=startcounter+1;
end

답변 (1개)

Ken Atwell
Ken Atwell 2015년 10월 16일
A semicolon at the end of the line suppresses output [ reference ], so displaying output is a matter of just remove the semicolon from your existing statement:
If you want to print out the value of endlocation in the inner loop, just remove the semi-colon:
endlocation=stop{1,1}(endcounter)
If you want to print out the value in the outer loop, add a new line with just the variable name (and no semi-colon) where/when you want it displayed.
endlocation
  댓글 수: 2
JE
JE 2015년 10월 16일
550317
So this is the number that it displays, however, I thought it would display each location inside the array every time and place those values into a new array. Am I missing something?
Ken Atwell
Ken Atwell 2015년 10월 16일
The entire array will be displayed, but endlocation looks to a scalar (non-array) value.
If you're trying to debug this, I recommend settings a breakpoint and single-stepping through this loop. Keep you eyes on the Workspace windows and look for unexpected values.

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

카테고리

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