display value in message box (2024)

39 views (last 30 days)

Show older comments

son on 20 Aug 2014

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box

Commented: Image Analyst on 17 May 2020

Accepted Answer: Star Strider

Open in MATLAB Online

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 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Star Strider on 20 Aug 2014

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149282

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149282

Open in MATLAB Online

Is this:

h = msgbox(sprintf('You chose %d',a))

something like what you want to do?

2 Comments

Show NoneHide None

son on 20 Aug 2014

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_232692

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_232692

Edited: son on 20 Aug 2014

Open in MATLAB Online

hi, i use sprintf code but now it can't display the special symbol alpha

clear all

close all

%%Insert value in Matlab

dlg_title = 'Insert Factor Value';

x1 = inputdlg('Enter number of channels:',dlg_title, [1 50]);

n = str2num(x1{:});

x2 = inputdlg('Enter input power for each channel (mW):',dlg_title, [1 50]);

p = str2num(x2{:})*10^-3;

x3 = inputdlg('Enter channel spacing (nm):',dlg_title, [1 50]);

delta_lambda = str2num(x3{:})*10^-9;

CreateStruct.Interpreter = 'tex';

CreateStruct.WindowStyle = 'modal';

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

alphadb = 0.20;

dispersion=16;

slope=0.080;

A=80;

elseif choice==2

alphadb = 0.22;

dispersion=0;

slope=0.075;

A=50;

else

alphadb = 0.23;

dispersion=3;

slope=0.050;

A=72;

end

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);

Star Strider on 20 Aug 2014

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_232703

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_232703

Open in MATLAB Online

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);

Sign in to comment.

More Answers (3)

Image Analyst on 20 Aug 2014

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149287

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149287

Open in MATLAB Online

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 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Ben11 on 20 Aug 2014

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149283

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149283

Open in MATLAB Online

You can use sprintf to format the message:

Message = sprintf('The value selected is %d\n',a);

h = msgbox(Message)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

son on 20 Aug 2014

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149284

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#answer_149284

woa, so easy, many thanks

4 Comments

Show 2 older commentsHide 2 older comments

Star Strider on 20 Aug 2014

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_232686

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_232686

My pleasure!

Eduardo Rey on 11 Mar 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_808808

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_808808

Edited: Eduardo Rey on 11 Mar 2020

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 on 17 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_848491

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_848491

Open in MATLAB Online

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 on 17 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_848697

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box#comment_848697

Open in MATLAB Online

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)

display value in message box (12)

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABProgrammingFunctionsFunction Creation

Find more on Function Creation in Help Center and File Exchange

Tags

  • display-message-box-matlab

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


display value in message box (13)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

display value in message box (2024)
Top Articles
The law finally caught up with notorious Philadelphia landlord Phil Pulley ... but for voting fraud
First car forfeited in Portland under new street racing law is a busted Mustang
Global Foods Trading GmbH, Biebesheim a. Rhein
Edina Omni Portal
فیلم رهگیر دوبله فارسی بدون سانسور نماشا
Don Wallence Auto Sales Vehicles
Yi Asian Chinese Union
When Is the Best Time To Buy an RV?
Edgar And Herschel Trivia Questions
Ap Chem Unit 8 Progress Check Mcq
Helloid Worthington Login
Https://Store-Kronos.kohls.com/Wfc
Northern Whooping Crane Festival highlights conservation and collaboration in Fort Smith, N.W.T. | CBC News
boohoo group plc Stock (BOO) - Quote London S.E.- MarketScreener
Clear Fork Progress Book
The Ultimate Style Guide To Casual Dress Code For Women
Loves Employee Pay Stub
The Pretty Kitty Tanglewood
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Ups Drop Off Newton Ks
Dragonvale Valor Dragon
Pirates Of The Caribbean 1 123Movies
Walgreens Bunce Rd
The Eight of Cups Tarot Card Meaning - The Ultimate Guide
Wolfwalkers 123Movies
Weather Underground Durham
Ordensfrau: Der Tod ist die Geburt in ein Leben bei Gott
Rek Funerals
R/Mp5
Elanco Rebates.com 2022
A Plus Nails Stewartville Mn
Bi State Schedule
Frequently Asked Questions - Hy-Vee PERKS
Pnc Bank Routing Number Cincinnati
Newsday Brains Only
Gideon Nicole Riddley Read Online Free
Laurin Funeral Home | Buried In Work
Honda Ruckus Fuse Box Diagram
Pokemon Reborn Locations
Deshuesadero El Pulpo
Taylor University Baseball Roster
Craigslist En Brownsville Texas
Dogs Craiglist
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
Lonely Wife Dating Club בקורות וחוות דעת משתמשים 2021
Callie Gullickson Eye Patches
Disassemble Malm Bed Frame
Mathews Vertix Mod Chart
Exploring the Digital Marketplace: A Guide to Craigslist Miami
Avance Primary Care Morrisville
Egg Inc Wiki
Lake County Fl Trash Pickup Schedule
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5494

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.