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

2 次查看(过去 30 天)
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
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 个)

Sulaymon Eshkabilov
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 CenterFile Exchange 中查找有关 Develop 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