- Matlab does not need an initiation of variables as such (you can delete line 1)
- the closing quotation mark within the char array within msg in line 2 is missing
- the output format '%d' you chose is of type signed integer (sprintf - formatSpec)
Display string and variable value in a window in a GUI or different output
39 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
chris bowman
am 6 Dez. 2019
Kommentiert: Robert U
am 6 Dez. 2019
Hey everyone, I'm very rusty on my C and matlab skills but basically what i'm trying to do is find a way to display certain variable values in my code to display in a way that when the code is ran i can get my charts, graphs and displayed values all in different figure windows ect. I'm doing a statistics for engineers class and i've wasted more than enough time trying to figure out how to make what i want work so I was hoping someone could provide some guidance on what to do next.
The Problem: In the work space i have a median value labled Median_X and it has a value of 14.545 and the rest of the variables are the same.
Code i've attempted:
msg = '';
msg = sprintf('A=%d\n, Median_X);
msgbox(msg,'Output Params');
===> the display is in the box but it shows up as 14.545000000e.... i don't want that and i can't find a way to force it to just take 3 or 4 sig figs,
What i would like is to display something like in a message box but reads the following:
Parameters of the discrete random variable [X]
Standard Deviation=...
Mean=...
Median=...
Max value X=...
Min value X=...
Any help would be greatly appreciated!
0 Kommentare
Akzeptierte Antwort
Robert U
am 6 Dez. 2019
Bearbeitet: Robert U
am 6 Dez. 2019
Hi chris bowman,
there are some issues within the code snippet you provided:
In order to overcome these issues code lines might be changed fulfilling your described content:
stdDev = 3.8652e-5;
MeanVal = 15.8694;
Median_X = 14.545;
maxVal = 3862.69843;
minVal = -3.50654e2;
msg = sprintf(['Parameters of the discrete random variable [X]\n\n',...
'Standard Deviation = %.4g\n',...
'Mean = %.3f\n',...
'Median = %.4f\n',...
'Max value X = %.3f\n',...
'Min value X = %.4f\n'],...
stdDev,MeanVal,Median_X,maxVal,minVal);
msgbox(msg,'Output Params');
Kind regards,
Robert
2 Kommentare
Robert U
am 6 Dez. 2019
Thank you for your positive feedback. If you like my answer, please, vote for it by clicking on the "thumb up"-symbol.
In case it serves your needs and answers your question thoroughly, accept it.
Kind regards,
Robert
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Argument Definitions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!