필터 지우기
필터 지우기

Display string and variable value in a window in a GUI or different output

조회 수: 25 (최근 30일)
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!

채택된 답변

Robert U
Robert U 2019년 12월 6일
편집: Robert U 2019년 12월 6일
Hi chris bowman,
there are some issues within the code snippet you provided:
  • 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)
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
chris bowman
chris bowman 2019년 12월 6일
Absolutely perfect!!! Thank you so much, spent way too many hours trying to figure out how to make this work and you knocked it out effortlessly. Thank you Robert!
Robert U
Robert U 2019년 12월 6일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by