フィルターのクリア

Changing default figure toolbar button's callback in App designer

9 ビュー (過去 30 日間)
Petri
Petri 2019 年 6 月 6 日
回答済み: Aaron Ward 2021 年 1 月 19 日
So I have made a simple app with the App Designer and have run into some issues. I have a figure and some buttons on the app. Issue is that when I pan the figure it does not reset the axes properly, hence, there are white borders all around my figure.
I can manually fix this by triggering app.UIAxes.XLim and YLim with values taken from the size of the actual image in the figure. The issue is how do I trigger this.
There is already a "Reset View" button in the figure but does not work. It resets the figure to some values prior to me manually fixing the XLimand YLim so there are still white borders around my image. Appanretly there is an internal function resetplotview which could be used, but it does not seem to work.
I could make one extra button to my control panel which then does my own "reset", but I was thinking that there is already a "Reset View" button in the figure itself so maybe I can just change the callback function? Well I found the button by findall(app.UIAxes.Toolbar,'Tooltip','Restore View'); but if I change the ButtonPushedFcn to my own function it just gives me this error:
Warning: Undefined function 'restoreview' for input arguments of type
'matlab.ui.controls.ToolbarPushButton'.
Error while evaluating ButtonPushedFcn for axes toolbar.
I have the restoreview function in my script file:
function restoreview(e,d)
% Default ButtonPushedFcn for the reset view toolbar button
@(e,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true);
% Add our own end, which is to reset the axes manually
app.UIAxes.XLim=[0, im.XData(2)];
app.UIAxes.YLim=[0, im.YData(2)];
end
Any help?
I know I can use just a character vector as a callback and it'll execute it as command(s) but that's realllly not what I want to do.
  2 件のコメント
Bas Peters
Bas Peters 2019 年 7 月 10 日
Did you already find a solution? I have the same problem.
Petri
Petri 2019 年 11 月 4 日
編集済み: Petri 2019 年 11 月 4 日
EDIT: IT WORKS?!
So I decided to try the way I initially did not get to work and apparently it works.
restoreviewbtn.ButtonPushedFcn=...
{@restoreview,app,im}; % Change the callback function
% New callback function for restore view
function restoreview(e,d,app,im)
% Default ButtonPushedFcn for the reset view toolbar button
@(e,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true);
% Add our own end, which is to reset the axes manually
app.UIAxes.XLim=[0, im.XData(2)];
app.UIAxes.YLim=[0, im.YData(2)];
end
No clue whether this version would've worked when I was wrinting this question but at least it works in r2019b.
OLD VERSION:
Oh well this was an old one but in case someone else finds this problematic I found an ugly way around this.
restoreviewbtn.ButtonPushedFcn=...
'app.UIAxes.XLim=[0, im.XData(2)]; app.UIAxes.YLim=[0, im.YData(2)];';
Honestly, I don't remember what this exactly does but I assume it literally makes the function to that piece of string there.

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

回答 (1 件)

Aaron Ward
Aaron Ward 2021 年 1 月 19 日
I recently worked out another solution. Note this applies to R2020A (I haven't tested other versions). The steps are as follows:
  1. Create the toolbar without the 'restoreview' button.
  2. Create the 'restoreview' button via 'axtoolbarbtn' function.
  3. Create a 'ButtonPushedFcn' for the newly created button and supply the callback handle.
  4. In the callback function, reset the axis limits.
% step 1
app.tb = axtoolbar(app.axis, {'zoomin', 'zoomout', 'export'});
% step 2
btn = axtoolbarbtn(app.sagittal_axes_tb, 'push');
btn.Icon = 'restoreview';
% step 3
btn.ButtonPushedFcn = createCallbackFcn(app, @restoreview, true);
% step 4
function restoreview(app, event)
limits = [lower upper];
app.axis.XLim = limits;
app.axis.YLim = limits;
end

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by