- 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
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
chris bowman
el 6 de Dic. de 2019
Comentada: Robert U
el 6 de Dic. de 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 comentarios
Respuesta aceptada
Robert U
el 6 de Dic. de 2019
Editada: Robert U
el 6 de Dic. de 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 comentarios
Robert U
el 6 de Dic. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!