- 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
23 views (last 30 days)
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);
===> 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]
Max value X=...
Min value X=...
Any help would be greatly appreciated!
Robert U on 6 Dec 2019
Edited: Robert U on 6 Dec 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'],...