Mike dyers
Mike dyers

Reputation: 15

How to set the plot line at specific starting position?

How can I set the starting plot line at a specific (x,y) coordinate?

The code I have below reads in an image, displays this image and incrementally plots a line on top of this image from a starting position to an ending position. However, I would like the values to start at a specific position instead of the origin.

img = imread('sd.jpg');
image(img);
hold on
h = plot(NaN,NaN); 
hold on  
for ii = 1:15
    pause(0.05)
    set(h, 'XData', x(1:ii), 'YData', y(1:ii));
end

Upvotes: 1

Views: 135

Answers (1)

rayryeng
rayryeng

Reputation: 104514

You'd simply add an offset to each coordinate in your x and y arrays:

img = imread('sd.jpg');
image(img);
hold on
h = plot(NaN,NaN); 
hold on;

%// Define x and y offsets here
xoffset = ...;
yoffset = ...;

for ii = 1:15
    pause(0.05)
    set(h, 'XData', x(1:ii) + xoffset, 'YData', y(1:ii) + yoffset); %// Change
end

Upvotes: 2

Related Questions