Connecting different scatters with line

조회 수: 1 (최근 30일)
Ivan Abraham
Ivan Abraham 2017년 3월 5일
답변: Image Analyst 2017년 3월 5일
Let say I have the following:
set1=rand(2,10)
set2=rand(2,10)
scatter(set1(1,:),set1(2,:))
hold on
scatter(set2(1,:),set2(2,:))
How do I join the two different scatter plots with a line? The above example is bogus, but the idea is that I have two sets of scatter points that differ slightly in time, and I want to plot both of them on the same plots, and join the two by a line to see where each one moved.

답변 (1개)

Image Analyst
Image Analyst 2017년 3월 5일
Try this:
% Define data. x is in row 1, y is in row2.
set1=rand(2,10)
set2=rand(2,10)
% Plot lines between corresponding pairs
for k = 1 : size(set1, 2)
plot([set1(1,k), set2(1,k)], [set1(2,k), set2(2,k)], ...
'rs-', 'LineWidth', 2, 'MarkerSize', 10);
hold on
end
grid on;

카테고리

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