Connecting points of two scatterplots

조회 수: 22 (최근 30일)
Erin Flowerday
Erin Flowerday 2021년 6월 1일
편집: Adam Danz 2021년 6월 3일
I have two scatter plots and I want to connect the points from the one plot to the points of the other. I have this code:
scatter(cells(:,1),cells(:,2), 8, 'r', 'filled');
scatter(integrins(:,1),integrins(:,2), 8, 'g', 'filled');
I basically want to connect the red dot and the green dot.
I tried doing this,but there is a problem with the lengths of the vectors
plot(cells, integrins, '-k')
hold on
scatter(cells(:,1),cells(:,2), 8, 'r', 'filled');
scatter(integrins(:,1),integrins(:,2), 8, 'g', 'filled');
hold off
Anyone know how to do this?
  댓글 수: 1
Adam Danz
Adam Danz 2021년 6월 2일
편집: Adam Danz 2021년 6월 3일
How does that code connect the red and green dots?
Also, if there is not a one-to-one correspondence between the red and green coordinates, how should they be connected?

댓글을 달려면 로그인하십시오.

답변 (2개)

Adam Danz
Adam Danz 2021년 6월 1일
DEMO
Create data
x1 = sort(rand(1,10)*10);
x2 = sort(rand(1,10)*10);
y1 = rand(1,10)*2;
y2 = rand(1,10)*4;
Create scatter plot
figure
hold on
scatter(x1,y1, 30, 'r', 'filled');
scatter(x2,y2, 30, 'g', 'filled');
Add connector lines
  • The notation (:)' merely forces each array to become a row vector.
  • plot(x,y) creates a lines for each column of x and y.
  • x1,x2,y1,y2 must all have the same number of elements.
plot([x1(:)';x2(:)'], [y1(:)';y2(:)'], 'k-')

Image Analyst
Image Analyst 2021년 6월 2일
Did you try quiver()?

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by