Changing the same property of some axis children using subsasgn

5 ビュー (過去 30 日間)
Diaa
Diaa 2021 年 4 月 18 日
コメント済み: Diaa 2021 年 4 月 18 日
How to make the following code work in order to change the 'Visible' property of some children plots whose handles are stored in toHide using subsasgn?
f1 = figure;
ax1=axes(f1);
axis(ax1,'tight');
ax1.NextPlot = 'add';
plot(ax1,[1,2],[3,4],'DisplayName','graph 1')
plot(ax1,[1,2],1.5*[3,4],'DisplayName','graph 2')
plot(ax1,[1,2],2*[3,4],'DisplayName','three')
toHide = findobj(ax1,'-regexp','DisplayName','graph');
%% Method 1
toHide(:).Visible = {'off','off'};
%% Method 2
S = substruct('()',{':'},'.','Visible');
toHide(:).Visible = subsasgn( toHide , S , {'off','off'} );
  4 件のコメント
Jonas
Jonas 2021 年 4 月 18 日
you could use
for nr=1:numel(toHide)
S(1).type='()';
S(1).subs={nr};
S(2).type = '.';
S(2).subs = 'Visible';
toHide = subsasgn( toHide , S , 'off' );
end
if the objects could be indexed directly this would be more easy, but your Method 1 does not work in my matlab
Diaa
Diaa 2021 年 4 月 18 日
Thanks for the help.

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

採用された回答

Matt J
Matt J 2021 年 4 月 18 日
編集済み: Matt J 2021 年 4 月 18 日
I assume you know that subsasgn is called implicitly whenever you make an assignment statement, as in the following:
[toHide.Visible]=deal('off')
  4 件のコメント
Diaa
Diaa 2021 年 4 月 18 日
I thought it could be done without the need to use for-loop.
Matt J
Matt J 2021 年 4 月 18 日
No, it cannot be done solely with subsasgn, with no loops.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by