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

7 visualizzazioni (ultimi 30 giorni)
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 Commento
Rik
Rik il 30 Dic 2022
This depends on how you trigger them. So how do you trigger these error messages?

Accedi per commentare.

Risposta accettata

Voss
Voss il 30 Dic 2022
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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by