フィルターのクリア

customise colour for RegionZoomInteraction

3 ビュー (過去 30 日間)
Dee Chan
Dee Chan 2023 年 10 月 27 日
回答済み: Githin George 2023 年 11 月 6 日
Suppose I have the following zoom Interactions implemented on an Axes component (app.UIAxes) in the App Designer. Matlab's regionZoomInteraction implement a drag-and-draw box on the UIAxes to zoom into a certain region (see attachment). Is there any chance the colour of the box used in RegionZoomInteraction on any UIAxes may be changed from the default blue to some customisable colour?
app.UIAxes.Interactions = [regionZoomInteraction zoomInteraction];
enableDefaultInteractivity(app.UIAxes);
  2 件のコメント
Mann Baidi
Mann Baidi 2023 年 11 月 2 日
Hi
Can you please share a image of the box in RegionZoomInteraction or elaborate more how to display the box?
Dee Chan
Dee Chan 2023 年 11 月 2 日
I have added some elaboration and attached an image of the box before zoom. It's merely a matlab feature.

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

回答 (1 件)

Githin George
Githin George 2023 年 11 月 6 日
Hello,
It is my understanding that you would like to change the color of the rectangles drawn during the Zoom events specified by ‘Interactions’ property of the UIAxes. Unfortunately, there does not seem to be any options for Axes object that can directly change the color of the drawn rectangle or any mention of the same in MATLAB documentation.
As a workaround, you could use the 3 callback functions of UIFigure, namely “WindowButtonDownFcn”, “WindowButtonMotionFcn” and “WindowButtonUpFcn” in combination to recreate the behaviour of ‘regionZoomInteraction’ while specifying the ‘color’ property in a ‘rectangle’ object. I’ve attached an example implementation of the callbacks below.
properties (Access = public)
rectangle matlab.graphics.primitive.Rectangle
isDrawing logical % Description
end
% Callbacks that handle component events
methods (Access = private)
% Window button down function: UIFigure
function UIFigureWindowButtonDown(app, event)
% Get the current mouse position
currentPoint = app.UIAxes.CurrentPoint;
startX = currentPoint(1,1);
startY = currentPoint(1,2);
% Create a rectangle object with color red
app.rectangle = rectangle(app.UIAxes, 'Position', [startX, startY, 0, 0],'EdgeColor','r');
app.isDrawing = true;
end
% Window button motion function: UIFigure
function UIFigureWindowButtonMotion(app, event)
if app.isDrawing
% Get the current mouse position
currentPoint = app.UIAxes.CurrentPoint;
currentX = currentPoint(1,1);
currentY = currentPoint(1,2);
% Calculate the width and height of the rectangle
width = currentX - app.rectangle.Position(1);
height = currentY - app.rectangle.Position(2);
% Update the rectangle position
app.rectangle.Position(3) = width;
app.rectangle.Position(4) = height;
end
end
% Window button up function: UIFigure
function UIFigureWindowButtonUp(app, event)
app.isDrawing = false;
app.UIAxes.XLim = [app.rectangle.Position(1) app.rectangle.Position(1)+app.rectangle.Position(3)];
app.UIAxes.YLim = [app.rectangle.Position(2) app.rectangle.Position(2)+app.rectangle.Position(4)];
delete(app.rectangle)
end
end
I’ve attached a documentation link for the ‘rectangle’ function used to draw and change color of the box. https://www.mathworks.com/help/matlab/ref/rectangle.html
Please note that the above code covers only the case where you draw a rectangle from bottom-left corner to top-right corner.
I hope this helps.

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by