display value in message box
30 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi, please help.
i create a multiple choice box and then display value of a in a message box but i don't know how to put the value of 'a' in the message box.
close all
clear all
choice = menu('Choose optical fiber type','Single-mode fiber ( G.652 )','Dispersion-shifted fiber ( G.653 )','Non-zero dispersion-shifted fiber ( G.655 )');
if choice==1
a=1;
elseif choice==2
a=2;
else
a=3;
end
h = msgbox(Message)
0 commentaires
Réponse acceptée
Star Strider
le 20 Août 2014
Is this:
h = msgbox(sprintf('You chose %d',a))
something like what you want to do?
2 commentaires
Star Strider
le 20 Août 2014
In sprintf, single ‘\’ are control characters for it and will throw an error if sprintf doesn’t recognise a valid control sequence, so to get it to print a ‘\’ that the TeX interpreter will see and interpret requires a double ‘\\’.
This worked for me, displaying both alpha and lambda as special characters:
h = msgbox({sprintf('Fibre attenuation: \\alpha = %g (dB/km)',alphadb)
'Derivative dispersion coefficient: s = dD/d\lambda = 0.075 (ps/nm^2.km)' },'Standard Values',CreateStruct);
Plus de réponses (3)
Image Analyst
le 20 Août 2014
son, you don't need to get the handle from the message box if you don't ever use it. And you might want to use uiwait() and make it modal, rather than the way you and the others did it, so that it waits for the user to click OK before blasting onwards, executing subsequent code before the users have even had a chance to click OK yet.
message = sprintf('You clicked on button #%d,\nwhich set a = %f', choice, a);
uiwait(msgbox(message, 'modal'));
Alternatively you can use helpdlg() instead of msgbox() if you want an "text balloon" displayed or warndlg() if you want an exclamation point displayed.
uiwait(helpdlg(message)); % Has text balloon
uiwait(warndlg(message)); % Has exclamation symbol
Hope this helps. Vote for my answer if it was helpful additional information.
0 commentaires
Ben11
le 20 Août 2014
You can use sprintf to format the message:
Message = sprintf('The value selected is %d\n',a);
h = msgbox(Message)
0 commentaires
son
le 20 Août 2014
4 commentaires
Victoria Viridiana Cabrera Díaz
le 17 Mai 2020
Eduardo Rey, hope this helps
uiwait stops your code from keeping on running until you click 'ok' in the message box
uiwait(msgbox(sprintf('var1 name: %2.3g \n var2name: %2.3g',var1,var2)));
Image Analyst
le 17 Mai 2020
If you don't know how many there will be, you might want to display them all in a scrollable listbox. For example, if there were thousands of numbers you wouldn't want a msgbox.
r = rand(100, 1); % Your list of numbers.
list = num2str(r) % Turn into strings.
% Now display all the numbers in a scrollable listbox.
[indx,tf] = listdlg('ListString',list)
Voir également
Catégories
En savoir plus sur Maintain or Transition figure-Based Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!