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 :)
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 Exchange에서 Data 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