Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Jan
Jan il 20 Lug 2012
Modificato: Jan il 20 Lug 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' il 20 Lug 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'.

Accedi per commentare.

Risposta accettata

Arthur
Arthur il 20 Lug 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

Più risposte (1)

Fa'
Fa' il 20 Lug 2012
Thank you very much Arthur. Code it's ok now.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by