フィルターのクリア

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

3 ビュー (過去 30 日間)
Fa'
Fa' 2012 年 7 月 20 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by