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

2 次查看(过去 30 天)
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 个评论
Jan
Jan 2012-7-20
编辑:Jan 2012-7-20
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' 2012-7-20
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'.

请先登录,再进行评论。

采纳的回答

Arthur
Arthur 2012-7-20
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

更多回答(1 个)

Fa'
Fa' 2012-7-20
Thank you very much Arthur. Code it's ok now.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by