How do I pass variable from one function to another

Hi!
How can I make this code work? I can't seem to find a way to pass variable 'v' to a different local function.
Tahnk you!
function [v] = Popup(obj, handles , h_listbox)
parameters=detectImportOptions('Data.xlsx');
v = get(obj,'Value');
disp(v)
set(h_listbox,'String',datestr(readvars('Data.xlsx',parameters,'Sheet',v)))
end
function Listbox(obj,h_popupmenu ,h_8things, handles)
k = get(obj,'Value');
Data = (readmatrix("Data.xlsx","Range",'B2:X32','Sheet', v));
polarhistogram(Data(k,:),16)
end

 採用された回答

Voss
Voss 2022 年 1 月 16 日

0 投票

How about this?
function [v] = Popup(obj, handles , h_listbox)
parameters=detectImportOptions('Data.xlsx');
v = get(obj,'Value');
disp(v)
set(h_listbox,'String',datestr(readvars('Data.xlsx',parameters,'Sheet',v)))
end
function Listbox(obj,h_popupmenu ,h_8things, handles)
k = get(obj,'Value');
Data = (readmatrix("Data.xlsx","Range",'B2:X32','Sheet', get(h_popupmenu,'Value')));
polarhistogram(Data(k,:),16)
end
If that doesn't work, we would have to see how the callbacks are set.

4 件のコメント

Abrathamist
Abrathamist 2022 年 1 月 16 日
Unfortunately it did not fix the problem. My callbacks are set as following:
h_listbox=uicontrol('Parent',h_figure,...
'Tag','listbox1','Callback',{@Listbox, h_popupmenu,h_8things});
h_popupmenu=uicontrol(h_figure,...
'Tag','popupmenu1','Callback', {@Popup, h_listbox});
Thank you!
Voss
Voss 2022 年 1 月 16 日
Setting the listbox Callback to include the popupmenu as an argument will not work like that, because the popupmenu has not been created yet when the listbox is created. Try this instead:
h_listbox=uicontrol('Parent',h_figure,...
'Tag','listbox1');
h_popupmenu=uicontrol(h_figure,...
'Tag','popupmenu1','Callback', {@Popup, h_listbox});
set(h_listbox,'Callback',{@Listbox,h_popupmenu,h_8things});
function [v] = Popup(obj,~,h_listbox)
parameters=detectImportOptions('Data.xlsx');
v = get(obj,'Value');
disp(v)
set(h_listbox,'String',datestr(readvars('Data.xlsx',parameters,'Sheet',v)))
end
function Listbox(obj,~,h_popupmenu,h_8things)
k = get(obj,'Value');
Data = (readmatrix("Data.xlsx","Range",'B2:X32','Sheet', get(h_popupmenu,'Value')));
polarhistogram(Data(k,:),16)
end
Abrathamist
Abrathamist 2022 年 1 月 16 日
That works great! Thank you so much!
Voss
Voss 2022 年 1 月 16 日
Excellent! Glad it is working.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 1 月 16 日

コメント済み:

2022 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by