フィルターのクリア

How DISPLAY *value* and *text* in editbox in GUI MATLAB at the same time ?

6 ビュー (過去 30 日間)
muhammad zulhelmy
muhammad zulhelmy 2017 年 3 月 6 日
編集済み: Image Analyst 2017 年 3 月 7 日
handles.behaviour is a name for editbox
let say value A is 80000, therefore B will give an answer 8
i want to display 8 cm in editbox
How can i do that VALUE with TEXT together ???
What should be add in that command ???
Thank You So Much .....
  2 件のコメント
Adam
Adam 2017 年 3 月 6 日
編集済み: Adam 2017 年 3 月 6 日
Unless you want the user to be allowed to change the unit from cm to whatever they want I would advise against just joining it with a number in an edit box. It would be annoying for a user to edit (if I want to change the number in an edit box I just swipe everything and type my new number in, I don't want to have to fuss around selecting only the number part) and how do you interpret what they write if it is something other than 'cm'?
Just put the 'cm' in a text box next to a purely numeric edit box, or use a dropdown list of pre-defined options if you want the user to be able to change the unit.
Stephen23
Stephen23 2017 年 3 月 7 日
+1 for Adam's suggestion. It may be simpler to keep the numeric and unit data separate.

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

採用された回答

Image Analyst
Image Analyst 2017 年 3 月 6 日
編集済み: Image Analyst 2017 年 3 月 7 日
Try this:
handles.behaviour.String = sprintf('%.1f cm', B);
I'd advise you to use more descriptive variable names so your code doesn't look like an alphabet soup of confusing letters.
If you have a really old version of MATLAB, use the old fashioned, obsolete way:
set(handles.behaviour, 'String', sprintf('%.1f cm', B));
  2 件のコメント
muhammad zulhelmy
muhammad zulhelmy 2017 年 3 月 7 日
Thank You... but the answer appears like this 008.00000 cm is there any way to fixed this bro ?
Image Analyst
Image Analyst 2017 年 3 月 7 日
編集済み: Image Analyst 2017 年 3 月 7 日
The number to the right of the dot is how many digits of precision you'll have. If you want it fixed at 3 then use %.3f. If you want it at 2, use %.2f.
By the way, I agree with Adam that you should either put the units in a static text label to the right of the edit field, or use a drop down box (mysteriously called "popup" by MATLAB) if they need to change the units. Though you can do it like you want to if you code it up to be smart enough to handle it (like Adobe and Microsoft so for their products) in the case where the user edits the field. If you don't want users editing it, then just make it a static text label, not an edit text box field.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by