Trouble displaying uicontrol text when it's a decimal

4 ビュー (過去 30 日間)
Tanner
Tanner 2015 年 12 月 9 日
コメント済み: Tanner 2015 年 12 月 9 日
Hello,
I'm trying to display a title for a table I'm making, but I can't seem to get it to display numbers.
Here is the part of my code:
prompt={'Enter the mach number (from 1 to 5 by intervals of 0.2):'};
title='Message';
answer=inputdlg(prompt,title, [1 30]);
M=answer{1};
MachNumber=str2num(answer{1});
f = figure('Position',[350 -100 700 930]);
m=sprintf('Mach %.1f', MachNumber);
txt = uicontrol('Style','text','FontSize', 20, 'FontWeight',... %creates title
'bold', 'Position',[110 865 110 28],'String', m); %creates title
When I run it, it will only display "Mach" but not the following number. What I found interesting was that in the command window m shows up correctly, just not in the GUI panel.
>> m
m =
Mach 1.2
How can I fix this? I also want to keep the 1 decimal number format (1.0, 1.2, 1.4, etc.)
Thank you!

採用された回答

TastyPastry
TastyPastry 2015 年 12 月 9 日
When I run your code, the number doesn't show up. This is because your uicontrol() textbox isn't wide enough. I change the 'position' property to [110 865 160 28] and it shows up as 'Mach 1.2' for me.
  1 件のコメント
Tanner
Tanner 2015 年 12 月 9 日
Oops, overlooked that. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by