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
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 个评论

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 :)
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.
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? :)
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 Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by