Is it possible to use imrect and display an internal grid or lines which will drag with it?

2 visualizzazioni (ultimi 30 giorni)
Hi everybody,
I am plotting a draggable rectangle using imrect, but I would like to show the user the internal grid of this rectangle (i.e. lines which intersect in the middle of the rectangle).
I would also like these lines or grid to drag with the rectangle and thus maintain their location within it.
Is this possible? Could you use imline and somehow lock them to the vertices of imrect?
Here is the code I have so far:
if true
pox = randi([100 200],[1,500]);
poy = randi([100 200],[1,500]);
fig_check = figure;
plot(pox,poy,'ko'); % plot position data for user to see
axis([min(pox)-10,max(pox)+10,min(poy)-10,max(poy)+10]); % set axis limits to sensible values, with room for boxes
h = imrect(gca, [100,100,100,100]); % draw polygon using known box sizes
setColor(h,'blue'); % change impoly lines colour
lines = findall(h,'type','line'); % find line objects
set(lines,'linewidth',3); % set a new line width
addNewPositionCallback(h,@(p) title(mat2str(p,3))); % get new position when box is moved
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim')); % constrain box to within plot
setPositionConstraintFcn(h,fcn); % apply constraint
%%Pause script while user fixes box
ann2 = annotation('textbox', [0.5, .9, .1, .1], 'string',sprintf('\t...press the button when finished editing box %s',num2str(i))); % [x y w h] create annotation for user
u = uicontrol('Style', 'pushbutton', 'Callback', 'uiresume(gcbf)','BackgroundColor','k'); % create a button for the user to use, easier than going back to console
drawnow; % Don't know, if this is needed.
uiwait(fig_check); % wait for button press
boxnow = getPosition(h)
end

Risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by