Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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 comentarios
Jan
Jan el 20 de Jul. de 2012
Editada: Jan el 20 de Jul. de 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' el 20 de Jul. de 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'.

Iniciar sesión para comentar.

Respuesta aceptada

Arthur
Arthur el 20 de Jul. de 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

Más respuestas (1)

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

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by