MATLAB : draw a line till the target point

99 views Asked by At

I am testing a code to make a function so that first it draws a point on the given coordinates but when I click it draws a line from [0,0,0] till that given coordinates

x = 10
y = 20
z=30
plot3(x,y,z,'ok')
hold on
w = waitforbuttonpress;
if (w == 0)
    plot3(x,y,z,'--.b')
end

so far the the code works like this first it plots the following function enter image description here

and then when I click it just plots a dot with in the circle enter image description here I have also tried making a matrix from plot3(0:x,0:y,0:z,'--.b') but as I would not be knowing the actual coordinates(would be reading it from a file) so the vector size would not be equal for x , y , and z , what can i do ?

1

There are 1 answers

0
johnny On

I found the solution

x = 10
y = 20
z = 30
plot3(x,y,z,'og')
axis([0 100 0 100 0 100])
hold on
w = waitforbuttonpress;
if (w == 0)
    plot3(linspace(0,x,100),linspace(0,y,100),linspace(0,z,100),'--b')
end

solves my problem thanks anyways