MATLAB Answers

Changing the same property of some axis children using subsasgn

조회 수: 41(최근 30일)
Diaa 18 Apr 2021 14:15
댓글: Diaa 18 Apr 2021 21:15
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.NextPlot = 'add';
plot(ax1,[1,2],[3,4],'DisplayName','graph 1')
plot(ax1,[1,2],1.5*[3,4],'DisplayName','graph 2')
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
Diaa 18 Apr 2021 21:15
Thanks for the help.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 18 Apr 2021 16:16
편집: Matt J 18 Apr 2021 16:19
I assume you know that subsasgn is called implicitly whenever you make an assignment statement, as in the following:
  댓글 수: 4
Matt J
Matt J 18 Apr 2021 21:01
No, it cannot be done solely with subsasgn, with no loops.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by