Thread Subject: handles pass strings

Subject: handles pass strings

From: eematic ee

Date: 7 Nov, 2009 18:39:01

Message: 1 of 4

Do "handles" pass strings? I have a program that enters a string using a popup box and passes it using handles to a input callback then an Evaluation callback. The proces worked for a number. In the Evaluation callback there is an error:

if alpha = 'A' then
    delta = -delta;
end;

The error is in the equals statement in "if alpha = 'A' then". Does this mean that "handles" is not passing strings thru alpha to the Evaluation callback?

Subject: handles pass strings

From: ucd puri

Date: 7 Nov, 2009 19:02:02

Message: 2 of 4

i would say rather try
strcmp(alpha,'A') ---> strcmp is case sensitive
strcmpi(alpha,'A') ---> strcmpi is NOT case sensitive

Subject: handles pass strings

From: eematic ee

Date: 7 Nov, 2009 20:20:04

Message: 3 of 4

 strcmp(alpha,'A') works but I am not receiving the string from the popup box.

Check my code:

alpha = uicontrol('Style','popup','String','Beta|Gamma','position',[120,675,40,20],'Callback',(@h_alpha));

function h_alpha(hObject, eventdata, handles)
    alpha = str2double(get(hObject,'String'));
    handles = guidata(hObject);
    guidata(hObject, setfield(handles,'alpha',alpha));


Remember this works for numbers without the popup box!

Subject: handles pass strings

From: ucd puri

Date: 8 Nov, 2009 02:11:02

Message: 4 of 4

the h_alpha function works to seems fine for me.

if u are using the [ alpha = str2double(get(hObject,'String')); ] line in your function and passing string input from popup, it would set ur alpha value to NaN...

i mean
alpha = uicontrol('Style','popup','String','2|3','position',[120,675,40,20],'Callback',(@h_alpha));
will return alpha value as a number, but if u use
alpha = uicontrol('Style','popup','String','alpha|beta','position',[120,675,40,20],'Callback',(@h_alpha));
then what output do u expect from str2double('alpha') ??

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com