display value in message box
이전 댓글 표시
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)
채택된 답변
추가 답변 (3개)
Image Analyst
2014년 8월 20일
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.
Ben11
2014년 8월 20일
You can use sprintf to format the message:
Message = sprintf('The value selected is %d\n',a);
h = msgbox(Message)
son
2014년 8월 20일
0 개 추천
댓글 수: 4
Star Strider
2014년 8월 20일
My pleasure!
Eduardo Rey
2020년 3월 11일
편집: Eduardo Rey
2020년 3월 11일
How do I display a list of values in a message box? For example, I have 10 variables:
var1 = 10e-3
var2 = 12e-3
...and so on. Basically what I want it to look like is:
var1 name: 10e-3
var2 name: 12e-3
Victoria Viridiana Cabrera Díaz
2020년 5월 17일
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
2020년 5월 17일
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)

카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!