Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Othman Alkandri
Othman Alkandri le 10 Mai 2023
Commenté : Othman Alkandri le 12 Mai 2023
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

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 11 Mai 2023
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 commentaire
Othman Alkandri
Othman Alkandri le 12 Mai 2023
the ; and [{}] made it work for me thank you

Connectez-vous pour commenter.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 10 Mai 2023
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 commentaire
Othman Alkandri
Othman Alkandri le 11 Mai 2023
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by