How can we draw a customizable rectangular ROI on an axes using AppDesigner?

20 ビュー (過去 30 日間)
Marc McLean
Marc McLean 2019 年 3 月 19 日
コメント済み: Sean de Wolski 2019 年 10 月 31 日
Hello,
I need to draw a customizable rectangular ROI on an axes in AppDesigner:
I tried this in AppDesigner:
h = drawrectangle(app.FullImageUIAxes, 'Position', [25,25,50,50], 'LineWidth', [2], 'Color', [1 0 0]);
But I get this error: ROI parent must be a valid Axes object.
I know the axes reference is correct.
Next I tried:
h = drawrectangle(app.FullImageUIAxes, 'Parent', app.UIFigure, 'Position', [25,25,50,50], 'LineWidth', [2], 'Color', [1 0 0]);
But I get the same error.
How should the axes be referenced when using drawrectangle in AppDesigner?

採用された回答

Marc McLean
Marc McLean 2019 年 3 月 20 日
App Designer errors if the axes is produced through the App Designer GUI. However, if the axes is produced programatically, App Designer finds the axes correctly. To produce the axes programatically, for example:
app.FullImageUIAxes = axes(app.UIFigure, 'Units', 'Pixels', 'Position',[166,84,750,744], 'XTick', [], 'YTick', []);
Then you can use drawrectangle:
app.ROI = drawrectangle(app.FullImageUIAxes, 'Position', [app.ROIposition(1),app.ROIposition(2),app.ROIposition(3),app.ROIposition(4)], 'LineWidth', [1], 'Color', [1 0 0]);
You have to add listeners programatically since you cannot add them through App Designer in this case:
addlistener(app.ROI,'MovingROI', @(varargin)ROIMoving(app, app.ROI));
  4 件のコメント
Guojin Feng
Guojin Feng 2019 年 10 月 31 日
I see. This makes sense then. Thanks for replying on this.
Sean de Wolski
Sean de Wolski 2019 年 10 月 31 日
It's worth noting that this answer was true for 18b and 19a. With 19b, uiaxes is supported natively.

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2019 年 10 月 30 日
In 19b, this works on a uiaxes as well.
drawrectangle(uiaxes)

カテゴリ

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