cla reset stops UIAxesButtonDown from working

Technical Source
2 min readApr 1, 2023

--

Hello. I have a UIAxes that I plot on and I want to manually be able to add text where ever I click on the graph. I am using the following to do this UIAxesButtonDown(app, event) defined as:

ax=app.UIAxes;              
%set(ax, 'hittest', 'off');
cursorPos = ax.CurrentPoint(1,1:2);
app.curX=(cursorPos(1)); % Current Mouse Coords defined as a public property
app.curY=(cursorPos(2)); % Current Mouse Coords defined as a public property

This works and indeed after I have plotted a graph Im able to place the text where I click on the graph. (see the function myAddText below)

However, if I clear the UIAxes by

Cla(ax,’reset’)

Then this is where it stops working. I have played about with hittest etc and still no luck.

If I use the following instead to clear the UIAxes, it all works again

ax=app.UIAxes;
b=ax.Children
n=numel(b)
for i=1:n
delete(b(i))
end

So my questions are:

1: What is it with cla ‘reset’ that stops it working and how can I correct it

2: Is my alternative way of clearing the UIAxes good for removing all graphics objects on the UIAxes so I actually don’t need cla ‘reset;

function  myAddText(app)             
ax=app.UIAxes;
x=app.curX;% SavedMouse Coords
y=app.curY; % SavedMouse Coords
txt=app.AddTitleEditField.Value;
txt=horzcat('\leftarrow',txt);
text(ax,x,y,txt,'Color',cl,'FontSize',12,'Interpreter', 'tex','HorizontalAlignment','left','VerticalAlignment','middle');

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

cla(ax,'reset')

Resets the ButtonDownFcn callback. I haven’t tested this out, but can you just use this:

myFun = ax.ButtonDownFcn;
cla(ax,'reset')
ax.ButtonDownFcn = myFun;

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet