Draw a draggble rectangle (fill with color) on a subplot to change the values in another subplot.

3 ビュー (過去 30 日間)
Armindo
Armindo 2016 年 3 月 9 日
編集済み: Adam 2016 年 3 月 10 日
Hi I am trying to draw a rectangle that can be dragable (between the XLim of the subplot). When dragged some update is made in another subplot based on the x limits imposed by the position of the rectangle.
What I have done:
h = findobj(ax, 'Type', 'line' ); % get the handle of get the x data from subplot
xp=get(h,'xData'); % get subplot xData
yp = get(ax,'ylim'); % get subplot y limit
vert = [xp(1), yp(1);xp(1), yp(2);xp(100), yp(2);xp(100), yp(1)]; % create vertex coordinates
transparency = 0.5; facecolor =[ 0.3765 0.3765 0.3765 ]; % light grey
edgecolor = [0 0 0]; tcolor(1,1,1:3) = facecolor; % color
fac = [1 2 3 4]; % connect points to make square
dat.hPatch = patch('parent',ax,'Faces',fac,'Vertices',vert,'FaceColor',tcolor,'FaceAlpha',transparency,'edgecolor',edgecolor,'Visible','on', 'tag', 'hPatch');
1) This is the better approach?
2) If I maximise or minimize the image the subplots don't update properly (for instance one subplot shrink and another not) how force them to update?
3) How to make the rectangle move smoothly when dragged by the mouse?
Any help would be apreciated.

回答 (1 件)

Adam
Adam 2016 年 3 月 9 日
If you have the Image Processing toolbox
doc imrect
  6 件のコメント
Armindo
Armindo 2016 年 3 月 10 日
Hi Adam,
I already try that but I get an error saying invalid syntax. I am using matlab R2015B vs 8.6.
Adam
Adam 2016 年 3 月 10 日
編集済み: Adam 2016 年 3 月 10 日
Oops, sorry, that is the incorrect syntax when you add arguments. It should be:
@() OnRectPosChange( 'rect1', a )
to create an anonymous function.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by