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.

 Accepted Answer

Matt Fig
Matt Fig on 1 Oct 2012
Edited: Matt Fig on 1 Oct 2012
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 Comments

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.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!