I am trying to make a plot of different types of marks along a line generated by using ginput.
Let's say I have a line and there are a series of point generated by the ginput with a constant increment in x, shown as attached figure1. The position vectors are
X=[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22]
Then I have 2 set of position vectors that seperated from X which are
x1=[1 2 3 4 5 6 11 12 13 14 18 19 20 21] , x2=[7 8 9 10 15 16 17]
for the points in x1 I need to plot dash line and x2 i need plot straight line. The result can illustrated in figure2.
My code is as below. I have tried using X(end) and X(1) but what I hope is it can refer back the previous value such as the 7th x value in x2 should refer to the 6th x value in x1 by knowing the increment. The increment is not fix as 1, it just an example.
Anyone have idea about these?
axis([0 22 0 22]);hold onS = ginput(2);Sx = round(S(1,1));Sy = round(S(1,2));Ex = round(S(2,1));Ey = round(S(2,2));m =(Ey-Sy)/(Ex-Sx);c = Ey-m*(Ex);if Ex>Sx x = Sx:1:Ex; y = round(m*x+c); plot(x,y,'*','Color','b', 'MarkerSize',5); elseif Ex<Sx x = Sx:-1:Ex; y = round(m*x+c); plot(x,y,'*','Color','b', 'MarkerSize',5); endplot([Sx Ex],[Sy Ey],'x','Color','r', 'MarkerSize',10);hold on
Best Answer