Drawrectangle on multiple tiles or figures using clickcallback
2 ビュー (過去 30 日間)
古いコメントを表示
Juan Carlos Soto Flores
2021 年 1 月 12 日
コメント済み: Juan Carlos Soto Flores
2021 年 1 月 12 日
I have been able to add rectangles with drawrectangle with the mouse click callback, like this:
My main code for plotting:
ti1=nexttile;
im1=imagesc(pspp.pos_c_mm,pspp.pos_z_mm,dummie2);
ti3=nexttile;
im2=imagesc(pspp.pos_c_mm,pspp.pos_z_mm,dummie);
ti5=nexttile;
im3=imagesc(pspp.pos_c_mm,pspp.pos_z_mm,asymmetry);
linkaxes([ti1 ti3 ti5],'xy')
set([im1 im2 im3],'ButtonDownFcn',@ImageClickCallback);
My callback function:
function ImageClickCallback (objectHandle , eventData )
axesHandle = get(objectHandle,'Parent')
coordinates = get(axesHandle,'CurrentPoint');
coordinates = coordinates(1,1:2)
drawrectangle('Position',[coordinates(1)-10,coordinates(2)-10,20,20],'StripeColor','g','LineWidth',0.2);
end
With this I'm able to draw the rectangle in the image where the click was perfromed, and I would like to draw the rectangle in the 3 images simultaneously , so no matter what image you click, you will add in that same location a rectangle in the 3 images. Is that possible?
The 3 images have the same width and length.
2 件のコメント
Benjamin Kraus
2021 年 1 月 12 日
In future questions, I recommend using the code formatting tools to make your post easier to read (and thus more likely to get a response).
採用された回答
Benjamin Kraus
2021 年 1 月 12 日
編集済み: Benjamin Kraus
2021 年 1 月 12 日
When you call drawrectangle, you need to indicate which axes/tile you want to draw into. If you call drawrectangle three times, this should raw the same rectangle in each tile.
drawrectangle(ti1,'Position',[coordinates(1)-10,coordinates(2)-10,20,20],'StripeColor','g','LineWidth',0.2);
drawrectangle(ti3,'Position',[coordinates(1)-10,coordinates(2)-10,20,20],'StripeColor','g','LineWidth',0.2);
drawrectangle(ti5,'Position',[coordinates(1)-10,coordinates(2)-10,20,20],'StripeColor','g','LineWidth',0.2);
Depending on how the rest of your code is structured, you may need to pass the axes handles into your callback function. For example, modify your callback like this to pass your axes/tile handles into the callback:
set([im1 im2 im3],'ButtonDownFcn',@(o,e) ImageClickCallback(o,e,ti1,ti3,ti5));
Then modify your callback function to have three more inputs:
function ImageClickCallback (objectHandle, eventData, ti1, ti3, ti5)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!