How to plot two types of marking in one single line continuously?

1 visualización (últimos 30 días)
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 on
S = 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);
end
plot([Sx Ex],[Sy Ey],'x','Color','r', 'MarkerSize',10);
hold on

Respuesta aceptada

darova
darova el 26 de Abr. de 2019
Look
axis([0 22 0 22]);
ind = [1 2 3 4 5 6 11 12 13 14 18 19 20 21 22];
S = ginput(2);
n = ind(end);
x = linspace(S(1,1),S(2,1), n);
y = linspace(S(1,2),S(2,2), n);
cla
hold on
plot(x,y,'.b')
for i = 1:length(ind)-1
i1 = ind(i);
i2 = ind(i+1);
if (i2-i1 == 1) && mod(i1,2)
plot([x(i1) x(i2)], [y(i1) y(i2)], '-k')
elseif i2-i1 > 1
plot([x(i1+1) x(i2-1)], [y(i1+1) y(i2-1)], '-r')
end
end
plot([x(1) x(end)], [y(1) y(end)], 'xr','MarkerSize',10)
hold on
But dont know about this
export_fig_out.png

Más respuestas (0)

Categorías

Más información sobre Data Exploration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by