フィルターのクリア

How to make the error below each other in the text box

2 ビュー (過去 30 日間)
Othman Alkandri
Othman Alkandri 2023 年 5 月 10 日
コメント済み: Othman Alkandri 2023 年 5 月 12 日
Hello, guys, I am trying to have the errors below each other, and they are all in one line. Could you please see the code and give me some suggestions?
if V_breadth_min_check == 0
msg_V_breadth_min = sprintf('Error Loading Parameter V-breadth-min: %f', app.V_breadth_min);
msg = strcat(msg, msg_V_breadth_min, "%s\n%s"); % append the error message to msg
error = error + 1;
elseif V_breadth_min_check == 1
msg_V_breadth_min = sprintf('Loaded Parameter V-breadth-min: %f', app.V_breadth_min);
end
%V_breadth_max_check
if V_breadth_max_check == 0
msg_V_breadth_max = sprintf('Error Loading Parameter V-breadth-max: %f%s\n%s', app.V_breadth_max_check);
msg = strcat(msg, msg_V_breadth_max); % append the error message to msg
error = error + 1;
elseif V_breadth_max_check == 1
msg_V_breadth_max = sprintf('Loaded Parameter V-breadth-max: %f', app.V_breadth_max);
end
error_num = sprintf('# Error: %f%s\n%s', error);
msg = strcat(msg, error_num); % append the error message to msg
% error is used as a flag to see it three is any
% uploaded value vilotated the value range or type condution
if error == 0
msgbox(msg_load, 'Ship Specification Parameters is Loaded');
app.ShipSpecificationButton.BackgroundColor = [0.93,0.69,0.13];
elseif error >= 0
msgbox(msg, 'Error in Ship Specification Parameters', 'error', 'modal');
app.ShipSpecificationButton.BackgroundColor = [1.00,0.00,0.00];
end

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 5 月 11 日
Use { } in strcat() and ; (semicolon), to start a new error message from the following line in your msgbox. Here is the corrected code with my some dummy arbitrary input variables:
msg = ' ';
error =0 ;
app.V_breadth_min = 0;
app.V_breadth_max_check = 13;
V_breadth_min_check = [0 1 0 0];
V_breadth_max_check = [1 0 1 0];
for ii=1:4
if V_breadth_min_check(ii) == 0
msg_V_breadth_min = sprintf('Error Loading Parameter V-breadth-min: %f ', app.V_breadth_min);
msg = strcat([msg; {msg_V_breadth_min}]); % append the error message to msg
error = error + 1;
app.V_breadth_min = 0;
end
if V_breadth_max_check(ii) == 0
msg_V_breadth_max = sprintf('Error Loading Parameter V-breadth-max: %f ', app.V_breadth_max_check);
msg = strcat([msg; {msg_V_breadth_max}]); % append the error message to msg
error = error + 1;
app.V_breadth_max = 0;
end
error_num = sprintf('# Error: %d', error);
msg = strcat([msg; {error_num}]); % append the error message to msg
if error == 0
app.ShipSpecificationButton.BackgroundColor = [0.93,0.69,0.13];
elseif error >= 0
msgbox(msg, 'Error in Ship Specification Parameters', 'error', 'modal');
app.ShipSpecificationButton.BackgroundColor = [1.00,0.00,0.00];
end
end
  1 件のコメント
Othman Alkandri
Othman Alkandri 2023 年 5 月 12 日
the ; and [{}] made it work for me thank you

サインインしてコメントする。

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 5 月 10 日
Here is how I would do (see my some arbitrary numerical values for display):
msg_V_breadth_min = sprintf('#2 Error Loading Parameter V-breadth-min: %f \n', pi);
error_num = sprintf('#1 Error: %f \n %s \n %s \n', [pi, date, date]);
msg = error_num; % Dont use strcat!!! to append the error message to msg
msg = strcat([msg, msg_V_breadth_min]);
msgbox(msg, 'Error in Ship Specification Parameters', 'error', 'modal');
  1 件のコメント
Othman Alkandri
Othman Alkandri 2023 年 5 月 11 日
thank you a lot, I tired the flowing didn't work for me. Do you see what I am missing?
msg = ' '
error =0 ;
if V_breadth_min_check == 0
msg_V_breadth_min = sprintf('Error Loading Parameter V-breadth-min: %f \n %s \n %s \n', app.V_breadth_min);
msg = strcat([msg, msg_V_breadth_min]); % append the error message to msg
error = error + 1;
app.V_breadth_min = 0;
end
%V_breadth_max_check
if V_breadth_max_check == 0
msg_V_breadth_max = sprintf('Error Loading Parameter V-breadth-max: %f \n %s \n %s \n', app.V_breadth_max_check);
msg = strcat([msg, msg_V_breadth_max]); % append the error message to msg
error = error + 1;
app.V_breadth_max = 0;
end
error_num = sprintf('# Error: %d \n %s \n %s \n', error);
msg = strcat([msg, error_num]); % append the error message to msg
% error is used as a flag to see it three is any
% uploaded value vilotated the value range or type condution
if error == 0
%msgbox(msg_load, 'Ship Specification Parameters is Loaded');
app.ShipSpecificationButton.BackgroundColor = [0.93,0.69,0.13];
elseif error >= 0
msgbox(msg, 'Error in Ship Specification Parameters', 'error', 'modal');
app.ShipSpecificationButton.BackgroundColor = [1.00,0.00,0.00];
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by