Changing the same property of some axis children using subsasgn

8 views (last 30 days)
Diaa
Diaa on 18 Apr 2021
Commented: Diaa on 18 Apr 2021
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 Comments

Sign in to comment.

Accepted Answer

Matt J
Matt J on 18 Apr 2021
Edited: Matt J on 18 Apr 2021
I assume you know that subsasgn is called implicitly whenever you make an assignment statement, as in the following:
[toHide.Visible]=deal('off')
  4 Comments
Matt J
Matt J on 18 Apr 2021
No, it cannot be done solely with subsasgn, with no loops.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!