Clear axes in GUI using cla reset does not work for secondary axes?

61 ビュー (過去 30 日間)
Maarten
Maarten 2014 年 12 月 27 日
回答済み: Vince Wong 2021 年 10 月 7 日
Hi all,
I am having some trouble clearing an axes using the reset command below:
cla reset
I have created an axes with a secondary axis through the following command (the variables F, S, L and D are arrays):
set(get(handles.ax1, 'Parent'), 'HandleVisibility', 'on'); %set handle visibility to on
axes(handles.ax1); %make ax1 the current axis
x1 = F;
y1 = S;
y2 = L;
y3 = D;
hl1 = line(x1,y1,'Color','r'); %plot a line in the current axis
hl2 = line(x1,y2,'Color','g');
handles.ax2 = axes('Units', 'character'); %create a new axis and set units to be character
set(handles.ax2, 'Position',get(handles.ax1,'Position'),...
'YAxisLocation','right',...
'Color','none',...
'YColor','k'); %position the new axis on the earlier existing axis
hl3 = line(x1,y3,'Color','b','Parent',handles.ax2); %plot a line on the new axis
However, when I use the "cla reset" command, it does not reset the secondary axis I created, nor the data from the secondary axis.
How can I fix this?

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 12 月 27 日
編集済み: Geoff Hayes 2014 年 12 月 27 日
Maarten - where are you calling the line of code to clear the axes? When you call this line, do the objects from the first axes get cleared, or does nothing happen?
If you want to explicitly indicate which axes to clear, then try the following
cla(handles.ax2,'reset');
With the above, you should be clearing all objects that have visible handles on the specified axes. If this doesn't work, then verify that you have drawn the graphics on the second axes.
  8 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 1 月 3 日
Maarten - I would have to see the code that you are using to try and figure out what is causing the problem. You aren't creating a new axes each time the push button is pressed, correct? The only time the second axes should be created is on the first button press.
Maarten
Maarten 2015 年 1 月 14 日
Geoff, thanks for the help. I did not find the time to reply here, but in the end I used the following command:
cla(handles.ax1,'reset'); % Do a complete and total reset of the axes.
if isfield(handles,'ax2') %delete ax2 if it exists
delete(handles.ax2,'');
end

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

その他の回答 (3 件)

Ilham Hardy
Ilham Hardy 2014 年 12 月 30 日
What if,
set(get(handles.ax1, 'Parent'), 'HandleVisibility', 'on'); %set handle visibility to on
axes(handles.ax1); %make ax1 the current axis
cla(handles.ax1,'reset');
set(get(handles.ax2, 'Parent'), 'HandleVisibility', 'on'); %set handle visibility to on
axes(handles.ax2); %make ax1 the current axis
cla(handles.ax2,'reset');
  1 件のコメント
Maarten
Maarten 2014 年 12 月 30 日
That does not work, because the data of axis 1 is hidden.

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


Sean de Wolski
Sean de Wolski 2014 年 12 月 30 日
delete(allchild(handles.axes1))
  2 件のコメント
Maarten
Maarten 2015 年 1 月 2 日
This code did not work for the ax2, but thanks for the input.
Maarten
Maarten 2015 年 1 月 14 日
Almost the same code used, but I had to specify it to handles.ax2.
cla(handles.ax1,'reset'); % Do a complete and total reset of the axes.
if isfield(handles,'ax2')
delete(handles.ax2,'');
end

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


Vince Wong
Vince Wong 2021 年 10 月 7 日
%yyaxis(handles, 'right')
cla(handles)
yyaxis(handles, 'left')
cla(handles)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by