필터 지우기
필터 지우기

How to keep a certain axes unchanged

조회 수: 1 (최근 30일)
Abdurrehman
Abdurrehman 2017년 7월 16일
댓글: Image Analyst 2017년 7월 16일
I am using following statement to clear all axes in gui at once.
arrayfun (@cla,findall (0,'type','axes'));
The statement works well and clears all axes. But out of all axes I need to keep one axes not to be cleared as it displays logo. How to modify above statement so that said axes shouldn't be cleared.

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 16일
setdiff the results of the findall and the handles you want to keep.
  댓글 수: 2
Abdurrehman
Abdurrehman 2017년 7월 16일
Hi, thanks for the answer setdiff returns "1x0 empty Axes array" because the respective axes is also the part of findall. Can you please give an example to solve this issue, thanks again
Walter Roberson
Walter Roberson 2017년 7월 16일
>> a(1) = subplot(2,2,1); a(2) = subplot(2,2,2); a(3) = subplot(2,2,3); a(4) = subplot(2,2,4);
>> setdiff(findall (0,'type','axes'),a(2))
ans =
3×1 Axes array:
Axes
Axes
Axes
Perhaps you reversed the order of the parameters for setdiff() ?

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

추가 답변 (2개)

Image Analyst
Image Analyst 2017년 7월 16일
Since you probably have only a handful of known axes, just call cla on them separately. I mean, why complicate things???
% Clear axes 1, 2, 4, and 5, but not 3
cla(ax1,'reset')
cla(ax2,'reset')
cla(ax4,'reset')
cla(ax5,'reset')

Abdurrehman
Abdurrehman 2017년 7월 16일
I have multiple axes can't write many statements. Instead want to manage in 1 or 2 statement (s)
  댓글 수: 1
Image Analyst
Image Analyst 2017년 7월 16일
If you have too many axes, either your desktop is cluttered with dozens upon dozens of windows, or if they are all on a single figure, the axes will be very tiny. Hopefully you actually only have like 9 or fewer and can use my suggestion because it's easy to understand. And hopefully one day you will be able to write long programs with many statements. If you do use Walter's solution using setdiff() and arrayfun(), be sure to document your code well to make it maintainable, because I think that method is less obvious to someone who comes along trying to follow your code, especially without comments and explanation. Sure it's compact but that comes at a price of not being obvious what it does. I mean if you were inheriting someone's code, which would you prefer to inherit and maintain?

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by