GUI help

조회 수: 3 (최근 30일)
Nasir Qazi
Nasir Qazi 2012년 4월 3일
% In my GUI I am giving value to T e.g 370 as input , but on debug mode when I am trying to check T as input this gives me 1X3 char instead of 1, this causing error in my answer giving three values what can I add to make the input as single char
e.g in my code
T = get(handles.Red_Temp,'string'); where 'Red_Temp' is input string

채택된 답변

Jan
Jan 2012년 4월 3일
370 cannot be represented as single char.
'Red_Temp' cannot be the input string, because this is a field in a struct. handles.Red_Temp is the handle of an edit uicontrol. T is the string. This string has 3 characters if it is '370'. To convert is to a number use sscanf:
D = sscanf(T, '%g');
  댓글 수: 2
Nasir Qazi
Nasir Qazi 2012년 4월 3일
where do I add 'D' into my code just after 'T = str2double(get(handles.Red_Temp,'string'));'
Jan
Jan 2012년 4월 3일
I do not know your code, therefore I cannot suggest a valid position.
SSCANF is an alternative to STR2DOUBLE, so you do not need both.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Matt Kindig
Matt Kindig 2012년 4월 3일
Are you saying that your GUI requires a double input and not a char input? If so, you can just convert the string to a double, like
T = str2double(get(handles.Red_Temp,'string'))
This will be a 1x1 double matrix.

Otis
Otis 2012년 4월 3일
"get(handles.Red_Temp, 'string')" will return a string. If you expect that string to be a number, e.g. '370', then use the function str2double, which will return the actual number that the string represents:
T = str2double(get(handles.Red_Temp,'string'));
Note: If the entered string does not represent an actual number, str2double will return NaN.

카테고리

Help CenterFile 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