How can I pass options from popupmenu to another callback function?

2 views (last 30 days)
Hi all! I'm programming a GUI. I have a popup menu that enables to display differents signals depending on the option selected. In the callback function of popup menu I've write this code:
% Determine the selected data set.
str = get(source, 'String');
val = get(source,'Value');
% Set current data to the selected data set.
switch str{val}
case 'Delta' % User selects Delta.
current_data = delta;
case 'Theta' % User selects Theta.
current_data = theta;
case 'Alpha' % User selects Alpha.
current_data = alpha;
case 'Beta' % User selects Beta.
current_data = beta;
case 'Gamma' % User selects Gamma.
current_data = gamma;
end
Now I've to pass the option selected to a pushbutton's callback function that generates plot when pushed by users. How can I do this? It would very helpful for me to resolve this problem. Thanks in advance.
[EDITED, code formatted, Jan]
  2 Comments
Jan
Jan on 20 Jul 2012
Edited: Jan on 20 Jul 2012
Please learn how to format the code properly. E.g. follow the "About MATLAB Answers" link. It is always a good idea to follow the standards of a forum.
I do not understand the question. What exactly is the problem?
Fa'
Fa' on 20 Jul 2012
I'm sorry, next time I shall pay attention. I'm new in this forum and I've to learn standards.
I would to pass the option selected in a popupmenu to a pushbutton's callback function where I've to use this options to plot different signals. This is the code I've write in the callback of the pushbutton (for the first option) but does not works:
handles.band = get(handles.popupmenuband,'String');
if val == 1
axes(handles.axes2);
handles.power = spt(:,2);
plot(handles.assetempi,handles.power);
xlabel('Time [s]');
title('POWER');
end
Displays this line error
Undefined function or variable 'str'.

Sign in to comment.

Accepted Answer

Arthur
Arthur on 20 Jul 2012
You don't need to pass the selected option when the selection is made in the popup. The easiest is simply read out the popup value when you run the callback of the button.
the callback of the button should look like this:
choise = get(handles.popupmenuband,'Value'); %get selected band
switch choise
case 1
% plot alpha
case 2
%plot beta
case 3
%plot gamma
%(etcetera)
end

More Answers (1)

Fa'
Fa' on 20 Jul 2012
Thank you very much Arthur. Code it's ok now.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!