필터 지우기
필터 지우기

Draw a line from one point to ALL points

조회 수: 4 (최근 30일)
Delvin
Delvin 2013년 5월 19일
So ive plotted a set of x and y arrays. Then i plotted a mean.
How do i draw lines only from this mean to all other points?
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 19일
Can you be more clear, and post your code.

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

채택된 답변

Image Analyst
Image Analyst 2013년 5월 19일
Try this demo:
% Generate sample data
thePoints = 3*rand(20,2);
% Find the mean.
referencePoint = mean(thePoints, 1)
xMean = referencePoint(1);
yMean = referencePoint(2);
% Plot the points.
scatter(thePoints(:, 1), thePoints(:, 2), 'LineWidth', 3);
hold on;
plot(referencePoint(1), referencePoint(2),...
'ro', 'MarkerSize', 15, 'LineWidth', 3);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
grid on;
% Plot lines from the mean to all the other points.
for k = 1 : size(thePoints, 1)
x = thePoints(k, 1);
y = thePoints(k, 2);
line([x, xMean], [y, yMean], 'Color', 'k');
end
  댓글 수: 2
Delvin
Delvin 2013년 5월 19일
Thanks, i was about to use the for loop but thought there might be some sneaky hidden matlab command!
Image Analyst
Image Analyst 2013년 5월 19일
A for loop is fine, especially for some small amount of iterations. And if the number of points was huge, you wouldn't be doing this in the first place since all the lines would overlap and blend together making a big mess.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by