SET with a dynamic function handle?

3 ビュー (過去 30 日間)
Jay
Jay 2012 年 5 月 4 日
Hello,
I want to use the SET command inside a while loop, with the function handle changing each time through. Namely, I have a few listboxes (tagged listbox1, listbox2, listbox3 etc.) and based on a numerical condition, I want only up to a certain number of them to remain visible. This doesn't work, but may provide a better idea of what I'm shooting for:
%get the handles of all listboxes, get the corresponding tags
allHandleList = findobj('style','listbox')
allTagList = get(allHandleList,'Tag')%get the tags of all those handles
handles.numCores = str2double(getenv('Number_of_processors'))
n=1;
while n<=handles.numCores
%make a function handle based on each tag
fhandle=str2func(['handles.' allTagList{n}])
%use that function handle to change a PropertyValue
set(fhandle(),'Visible','off')
n=n+1; %update count variable
end

採用された回答

Walter Roberson
Walter Roberson 2012 年 5 月 4 日
No need to make a function handle.
fhandle = handles.(allTagList{n});
set(fhandle, 'Visible', 'off');
  2 件のコメント
Jay
Jay 2012 年 5 月 4 日
Thanks! didn't know I could create the function name like that.
Walter Roberson
Walter Roberson 2012 年 5 月 4 日
That's not a function name, that's a dynamic field name. "handles" is a structure.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by