How can i show multiple errors in one msgbox or errordlg ?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have 10 types of errors and i use errordlg function to show them ,but it shows one by one popup...
i want to show these errors in one window or one msgbox...
please help anyone i am new in matlab...
Thanku....!
댓글 수: 1
채택된 답변
Voss
2022년 12월 30일
You can store the error messages and pass them to errordlg when you want to report them.
For example, let's say you have a scalar variable "x" that must be a positive integer greater than 10. We'll split those conditions into three separate error checks, and report the checks that failed.
% define the error messages:
% three types of errors can occur in this example
error_msg = { ...
'x must be positive' ...
'x must be an integer' ...
'x must be greater than 10' ...
};
% logical vector saying which error(s) occurred (initially all false):
is_error = false(1,numel(error_msg));
% initialize a variable to keep track of which error/message we're on:
msg_idx = 0;
% first error check:
% x being non-positive is the first type of error:
msg_idx = msg_idx+1;
if x <= 0
is_error(msg_idx) = true;
end
% second error check:
% x not being an integer is the second type of error
msg_idx = msg_idx+1;
if mod(x,1) ~= 0
is_error(msg_idx) = true;
end
% third error check:
% x not being greater than 10 is the third type of error
msg_idx = msg_idx+1;
if x <= 10
is_error(msg_idx) = true;
end
% report the errors that occurred (if any):
if any(is_error)
error_msg = ['The following error(s) occurred:' error_msg(is_error)];
errordlg(sprintf('%s\n\n',error_msg{:}));
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!