Clear Filters
Clear Filters

Plot onto an image using drawnow

2 views (last 30 days)
Ashfaq Ahamed
Ashfaq Ahamed on 15 Sep 2015
I have the following code, which allows the user to plot points on a graph. What I would like to do is to change the background of the graph plot to show some image of a schematic. How would I go about doing this? I would also like the axes to represent pixel values to the nearest integer instead of floating points. Please help me out with this
function draw_lines
% Click the left mouse button to define a point
% Drag the mouse to draw a line to the next point and
% left click again
% Right click the mouse to stop drawing
%
clc
clear
figure('WindowButtonDownFcn',@wbdcb)
k=1;
ah = axes('DrawMode','fast');
grid on;
axis ([-1000 1000 -1000 1000])%open the file to save the coordinates into
fileID = fopen('coord.txt','w');
% hl = line('XData',0,'YData',0,'Marker','.');
% str=['(',num2str(0),num2str(0),')'];
%
% drawnow
function wbdcb(src,evnt)
if strcmp(get(src,'SelectionType'),'normal')
[x,y,str] = disp_point(ah); %write the coordinates into the file
A=[x,y];
fprintf(fileID,'%6.2f %6.2f\n',A); hl = line('XData',x,'YData',y,'Marker','.');
text(x,y,str,'VerticalAlignment','bottom');drawnow
set(src,'WindowButtonMotionFcn',@wbmcb)
elseif strcmp(get(src,'SelectionType'),'alt')
set(src,'WindowButtonMotionFcn','')
[x,y,str] = disp_point(ah); %write the coordinates into the file
A=[x,y];
fprintf(fileID,'%6.2f %6.2f\n',A); text(x,y,str,'VerticalAlignment','bottom');drawnow
fclose(fileID);
end
function wbmcb(src,evnt)
[xn,yn,str] = disp_point(ah);
xdat = [x,xn];
ydat = [y,yn];
set(hl,'XData',xdat,'YData',ydat);
end
end
function [x,y,str] = disp_point(ah)
% if k==1
% x=0;y=0;
% k=0;
% else
cp = get(ah,'CurrentPoint');
x = cp(1,1);y = cp(1,2);
% end
str = ['(',num2str(x,'%0.3g'),', ',num2str(y,'%0.3g'),')'];
end
end

Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!