Draw line between two points if x distance is longer than...

1 vue (au cours des 30 derniers jours)
Katerina Kunorzova
Katerina Kunorzova le 15 Mar 2021
I have scatter plot. I need draw line or something similar between two point if their x distance is longer than 2. I draw to picture.
Thank You!

Réponse acceptée

Rik
Rik le 15 Mar 2021
You can easily find the indices of such locations (assuming x and y are sorted along x):
x=[linspace(-16,-8,200) linspace(-5.5,2,200)];
y=rand(size(x));
ind=find(diff(x)>=2);
plot(x,y,'.b'),hold on
for n=1:numel(ind)
plot(x(ind(n)+[0 1]),y(ind(n)+[0 1]),'b');
end
hold off

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by