Entering a value for 'String'

When 'String','' and enter the value in manually it works. When 'String','100' it does not.
vi = uicontrol('Style','edit','String','100','position',[10 630 100 20],'Callback',(@h_vi));
How do I correct this?

回答 (4 件)

Image Analyst
Image Analyst 2015 年 9 月 10 日

0 投票

630 is too big - it's off screen, try [10 30 100 20] instead.
Philosophaie
Philosophaie 2015 年 9 月 10 日
編集済み: Philosophaie 2015 年 9 月 10 日

0 投票

This is the error I get. I do use str2double to convert vi and angle.
Error code:
Undefined function 'mpower' for input arguments of type 'matlab.ui.control.UIControl'.
Error in ProjectileMotion>Evaluate (line 55)
maxh = vi^2/(2*9.81)*(sin(angle*pi/180))^2;
Error while evaluating UIControl Callback
Image Analyst
Image Analyst 2015 年 9 月 10 日

0 投票

You can't raise and edit field itself to a power. You have to get the number out of the edit field first, then raise it to a power.
% Create an edit field. The "handle" to it is called hEdit.
hEdit = uicontrol('Style','edit','String','100','position',[10 30 100 20],'Callback',(@h_vi));
% Get string out of the edit field and then convert it to a double variable.
vi = str2double(get(hEdit, 'String'));
% Now do the mathematical equation.
maxh = vi^2/(2*9.81)*(sin(angle*pi/180))^2;
Of course vi will be 100 since you gave no time for the user to change it before you pulled out the 100 and used it.

1 件のコメント

Image Analyst
Image Analyst 2015 年 9 月 11 日
By the way, you can use sind(angle) instead of sin(angle*pi/180).

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

Philosophaie
Philosophaie 2015 年 9 月 10 日
編集済み: Philosophaie 2015 年 9 月 10 日

0 投票

I did that for both vi and angle.
vi = str2double(get(hEdit, 'String'));

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2015 年 9 月 10 日

コメント済み:

2015 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by