How it is possible to pass variables from the script into a Callback function?

10 ビュー (過去 30 日間)
Parham Ebrahimi
Parham Ebrahimi 2019 年 7 月 4 日
コメント済み: Parham Ebrahimi 2019 年 7 月 4 日
I have written the following code in which couple of checkboxes will be generated on a plot.
Now, I want to make it in a way that for every checkbox, a specific plot is being shown if the checkbox is checked by the user.
The problem is I can not use the variables such as my loop index inside the Callback function.
I would appreciate if someone could help me.
for i=1:AnSwer
cellwithstruct=d.channels(i);
chkbox=uicontrol('Style','checkbox','String',cellwithstruct{1}.name,'position',[10 25*(i-1) 60 20], ...
'Callback',@myCallbackfunc);
plot(time_vector,d.samples(i,:));grid minor;%This is the plot that I want to use inside the Callback function
end
The format for callback function is:
function myCallbackfunc(hObject, ~, ~)
if (get(hObject,'Value') == get(hObject,'Max'))
%The plot should be done here;
else
%The plot should be erased here;
end
end
  4 件のコメント
Parham Ebrahimi
Parham Ebrahimi 2019 年 7 月 4 日
編集済み: Parham Ebrahimi 2019 年 7 月 4 日
Dear Adam,
Thank you very much. Very useful!
Parham Ebrahimi
Parham Ebrahimi 2019 年 7 月 4 日
Thank you dear Stephen. Useful link!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by