フィルターのクリア

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

5 ビュー (過去 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 日
thanku
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