loop not working for negative value
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
Hi to all , Attached please find the file in which loop is not working for the negative value. when random number is added to negative value the reduced value is not displayed as it happens for positive value....... Regards
댓글 수: 0
답변 (1개)
  Walter Roberson
      
      
 2015년 11월 20일
        In your code you have
        if x > 0
        x_new = x - dx
        if x_new < x
            x = x_new
        else x = x
        end
        if x < 0
The "end" you see there is for the "if x_new < x", so structurally this is like
        if x > 0
        x_new = x - dx
        ... assign something to x ...
        if x < 0
Notice that you have not ended the "if x > 0" at the time you check "if x < 0". That might be deliberate, but it also means that if the value was initially negative then the "if x > 0" would not have succeeded and so you would not have reached the "if x < 0" line.
Your code is not commented so we cannot determine what you are intending to do.
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

