cla reset stops UIAxesButtonDown from working

3 ビュー (過去 30 日間)
Jason
Jason 2023 年 3 月 23 日
コメント済み: Image Analyst 2023 年 3 月 23 日
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');

採用された回答

Cameron
Cameron 2023 年 3 月 23 日
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;
  2 件のコメント
Jason
Jason 2023 年 3 月 23 日
Yes that works, thanks.
Can you comment on my alternative way to do it.
Image Analyst
Image Analyst 2023 年 3 月 23 日
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2023 年 3 月 23 日
If yoiu just want to clear the axes without disconnecting your callback function why not call cla without 'reset':
cla(app.UIAxes);
  1 件のコメント
Jason
Jason 2023 年 3 月 23 日
Hi I.A. Well I guess its historic, Im usually working with images, and load up upto 500 at a time - and repeat this say 20 times throught the day. When I used to exclude the 'reset' option, I believe I had some kind of memory leak with something being left on the axes everytime. It ended up with my matlab session freezing and needed to be closed. When I started to sue the 'reset' option I never had any problems.

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

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by