How to stop a script if conditions are met.
조회 수: 1,628 (최근 30일)
이전 댓글 표시
I am using the 'if' function to detect if a user inputs a number that is not 5 digits long. What I would like is a function that stops the script if a certain condition is met without displaying an error message.
P.S. I'm very new to MATLAB.
댓글 수: 1
Jingyang Xie
2021년 1월 6일
Hi Cory, have you solved this problem? I think I encountered the same problem...
채택된 답변
Walter Roberson
2012년 2월 2일
편집: MathWorks Support Team
2018년 11월 9일
댓글 수: 9
Muhammad Usman Saleem
2022년 11월 5일
Respected Sir @Walter Roberson, I not get the point your shared. Will you please amend this suggestion in my code shared above please?
Walter Roberson
2022년 11월 5일
notdone = true(9,1);
while any(notdone)
if rcp(i,m)<0.1 & trcp(i,m) > 0.8
ECP{i,m}=Ecp{i,m};
notdone(1) = false;
end
if recp(i,m)<0.1 & trecp(i,m) > 0.8
ECN{i,m}= Ecn{i,m};
notdone(2)=false;
end
%etc
end
추가 답변 (1개)
Hamid Ramezani
2019년 9월 30일
you may use "error" function instead of return
댓글 수: 3
Adam K
2020년 12월 10일
편집: Adam K
2020년 12월 10일
I think a 'msgbox' to really alert the user what is the issue, and then the 'error' funcition to stop the code would be a workaround. This way the user is aware that the issue is not really an 'error' when they see the red error font.
msg = "You've got a number that is not 5 digits long";
f = msgbox(msg)
error(msg)
Rik
2020년 12월 10일
I wonder if it is possible to detect if the code is running in a try block. In such cases the message might be more confusing than simply throwing the error.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!