フィルターのクリア

Branching a WindowButtonDown function

2 ビュー (過去 30 日間)
Jason
Jason 2020 年 1 月 26 日
回答済み: J. Alex Lee 2020 年 1 月 26 日
Hi. I have written a windowsButtonDown function (in App Designer) to report back the coordinates of a plot on a UIAxes component.
function figure1WindowButtonDown(app, event)
%Remove any previous drawn "roi point object" that is used to indicate the position clicked on the UIAXes
delete(findobj(app.UIAxes,'type','images.roi.Point'));
z=app.UIAxes.CurrentPoint;
x=z(1,1); y=z(1,2);
%Determine if user clicked on UIAxes
if x >= app.UIAxes.XLim(1) & x <= app.UIAxes.XLim(2) & y >= app.UIAxes.YLim(1) & y <= app.UIAxes.YLim(2)
app.xyAX1=[x,y]; %Save for later use
drawpoint(app.UIAxes,'Position',[x y]);
end
Whilst this works, I also want to use a button down function on a seperate UIAxes4 which holds a greyscale Image (16 bit). (The idea is read back the value on the image at the location as the useful impixelinfo tool (for GUIDE) doesn't work with appdesigner yet.
So I put another if statement in:
%See if user selects the Image (UIAxes 4)
if x >= app.UIAxes4.XLim(1) & x <= app.UIAxes4.XLim(2) & y >= app.UIAxes4.YLim(1) & y <= app.UIAxes4.YLim(2)
delete(findobj(app.UIAxes4,'Marker','+')); %Remove any previously drawn '+'
z=app.UIAxes4.CurrentPoint;
x=round(z(1,1)); y=round(z(1,2));
hold(app.UIAxes4,'on');
plot(app.UIAxes4,x,y,'r+') %Visualise positon on image
% TODO....Then will get value from image at this location
end
But it doesnt seem to be branching correctly, when I click on UIAxes not only does it draw the point (via drawpoint) on the UIAxes, it also does on the UIAxes4 (and resizes the image weirdly!)

採用された回答

J. Alex Lee
J. Alex Lee 2020 年 1 月 26 日
If you don't mind using undocumented features, I have had success using the standard axes() object instead of uiaxes(), because it still supports the axes's own buttondownfcn. You can make a placeholder uipanel in app designer, then in a startupfcn create an axes in the panel (be sure to declare a custom property to hold that axes object) with the appropriate buttondownfcn.
I think this is the cleaner way within current matlab limitations, to avoid branching on the figures windowbuttondownfcn.
At least with 2019b, I can confirm this doesn't break when creating a web app.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying 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