How can i show multiple errors in one msgbox or errordlg ?

조회 수: 7 (최근 30일)
Shri.s
Shri.s 2022년 12월 30일
댓글: Shri.s 2022년 12월 31일
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
Rik
Rik 2022년 12월 30일
This depends on how you trigger them. So how do you trigger these error messages?

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

채택된 답변

Voss
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
  댓글 수: 2
Shri.s
Shri.s 2022년 12월 31일
I find my solution in errordlg box in its referance page....

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

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by