Command for Stopping the Analysis
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
When a variable (x) exeed the limit value (y) doing so after 5 times then stop the analysis. 
채택된 답변
  Image Analyst
      
      
 2023년 5월 22일
        Try something like this
exceedCount = 0;
for k = 1 : 1000000
    % First update x in the loop.  Then compare it to y.
    if x > y
        % x is greater than y.  
        % Increment the count of how many times this has happened.
        exceedCount = exceedCount + 1;
        % Quit loop if x has exceeded y 5 times.
        if exceedCount >= 5
            break;
        end
    end
end
댓글 수: 7
  Image Analyst
      
      
 2023년 5월 26일
				Seems inefficient, but you can do
exceedCount = 0;
for k = 1 : 1000000
    % First update x in the loop.  Then compare it to y.
    if (u0 < ut) && (u0 > uc) % Signal is above min and below max.
        % u0 is in the acceptable range.  
        % Do whatever.
    else
        % u0 is out of the acceptable range.  
        % Increment the count of how many times this has happened.
        exceedCount = exceedCount + 1;
        % Quit loop if x has exceeded y 5 times.
        if exceedCount >= 5
            break;
        end
    end
end
To learn other fundamental concepts, invest 2 hours of your time here:
추가 답변 (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!



