Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
GUIDE (passing variables)

Subject: GUIDE (passing variables)

From: Daniel

Date: 14 Jun, 2007 15:33:04

Message: 1 of 4

Hello all,
I am a novice in the use of GUIDE so I apologize if my question is
ridiculous.
I have implemented a GUI with a pop-up menu and a pushbutton. The
pop-up menu implements three values 1,2,3 and I collect one of this
values according to the preferences of the user. The pushbutton calls
to the function suma(a) which parameter is got of the values of the
pop-up menu and passed to the function suma when we push the
pushbutton.
How can I pass this value from the pop-up menu to the pushbutton.
The code I have implemented is the following:

(inside pop-up menu callback)
a=double(get(hObject,'Value'))
set(handles.pushbutton1.a,'Value',a);

(inside pushbutton callback)
suma(a);

where the function suma(a) is:
function []=suma(a)
b=4+a;
b
return

Thank you very much for your help,
Regards,
Daniel

Subject: GUIDE (passing variables)

From: Joseph

Date: 14 Jun, 2007 16:07:42

Message: 2 of 4

Looks like you're close. If I remember correctly, everything should
work if you put a get in the pushbutton callback

 Daniel wrote:
>
>
> Hello all,
> I am a novice in the use of GUIDE so I apologize if my question is
> ridiculous.
> I have implemented a GUI with a pop-up menu and a pushbutton. The
> pop-up menu implements three values 1,2,3 and I collect one of this
> values according to the preferences of the user. The pushbutton
> calls
> to the function suma(a) which parameter is got of the values of the
> pop-up menu and passed to the function suma when we push the
> pushbutton.
> How can I pass this value from the pop-up menu to the pushbutton.
> The code I have implemented is the following:
>
> (inside pop-up menu callback)
> a=double(get(hObject,'Value'))
> set(handles.pushbutton1.a,'Value',a);
>
> (inside pushbutton callback)
> suma(a);
>
> where the function suma(a) is:
> function []=suma(a)
> b=4+a;
> b
> return
>
> Thank you very much for your help,
> Regards,
> Daniel

Subject: GUIDE (passing variables)

From: Daniel

Date: 14 Jun, 2007 16:37:29

Message: 3 of 4

Excuse me, but I wrote wrong the code. Can you tell me which would be
the correct code inside of pushbutton and popup menu callbacks? How
can I use the get function?
I have:
(inside pop-up menu callback)
a=double(get(hObject,'Value'))

(inside pushbutton callback)
suma(a);
 
Thank you very much for your help,
Regards,
Daniel

Joseph wrote:
>
>
> Looks like you're close. If I remember correctly, everything
> should
> work if you put a get in the pushbutton callback
>
> Daniel wrote:
>>
>>
>> Hello all,
>> I am a novice in the use of GUIDE so I apologize if my question
> is
>> ridiculous.
>> I have implemented a GUI with a pop-up menu and a pushbutton.
The
>> pop-up menu implements three values 1,2,3 and I collect one of
> this
>> values according to the preferences of the user. The pushbutton
>> calls
>> to the function suma(a) which parameter is got of the values of
> the
>> pop-up menu and passed to the function suma when we push the
>> pushbutton.
>> How can I pass this value from the pop-up menu to the
pushbutton.
>> The code I have implemented is the following:
>>
>> (inside pop-up menu callback)
>> a=double(get(hObject,'Value'))
>> set(handles.pushbutton1.a,'Value',a);
>>
>> (inside pushbutton callback)
>> suma(a);
>>
>> where the function suma(a) is:
>> function []=suma(a)
>> b=4+a;
>> b
>> return
>>
>> Thank you very much for your help,
>> Regards,
>> Daniel

Subject: GUIDE (passing variables)

From: Jerome

Date: 15 Jun, 2007 04:27:44

Message: 4 of 4

Hi,

try this :

(inside pop-up menu callback)
handles.a=get(hObject,'Value');
guidata(gcbf,handles)

(inside pushbutton callback)
handles=guidata(gcbf);
suma(handles.a);

Jérôme

Tags for this Thread

No tags are associated with this thread.

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.

Contact us