Gui interface code question.

Hello there :), Im coding for a converter Gui. Im a starter so im having troubles in using codes. anyways..I just wanna know how can multiply variables in gui?
screen = get(handles.text1, 'String');
screen = (screen*2.54);
set( handles.text1, 'String', screen)
this is my code for converting an expected input of inch to centimeters, what is wrong here? the answer I get is wrong.

 採用された回答

Matt Fig
Matt Fig 2012 年 10 月 1 日
編集済み: Matt Fig 2012 年 10 月 1 日

1 投票

What you need to remember is that you are getting a string, not a number. If you want to use it as a number, you must convert from a string to a number. Then if you want to use the result as a string you need to convert from a number to a string.
screen = str2double(get(handles.text1, 'String'));
screen = (screen*2.54);
set( handles.text1, 'String', num2str(screen))

4 件のコメント

jaybee
jaybee 2012 年 10 月 1 日
I just wanna ask whats the use of num2str,strcal and str2double? Im sorry for asking so much questions, im just interested in doing this project so i want to know whats happening to the program. btw, thankyou for answering :)
Matt Fig
Matt Fig 2012 年 10 月 1 日
Whenever you see a function in MATLAB that you haven't encountered before, a good thing to do is to read the help for it.
help str2double
help num2str
I cannot find strcal.
jaybee
jaybee 2012 年 10 月 1 日
heey, i think i got a problem with the code, it works fine for a single number but when I enter an expression, it just prints NaN
exp1
input:1
output:2.54(so it worked)
exp2:
input:1/2
output:NaN.
why does this happen? i tried using eval() but I think it doesn't evaluate double. what could i do? :)
Matt Fig
Matt Fig 2012 年 10 月 1 日
Did you read the help for STRDOUBLE as I suggested? If you had done so, you would see that strings of the type '1/2' are not listed as valid inputs for this function...
Please take the time to read the help for the functions you are using. Take note that there are alternative functions (listed at the end of the help for STR2DOUBLE!!) that will work with such strings.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2012 年 10 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by