Combining two plots and adding color to points

2 ビュー (過去 30 日間)
TS
TS 2015 年 5 月 5 日
編集済み: Image Analyst 2015 年 5 月 5 日
matrix=load('Data');
x = matrix(:,1);
y = matrix(:,2);
fprintf('The maximum distance between two points is %3.2f units.\n',hypot((max(x)-min(x)), (max(y)-min(y))))
plot([max(x),max(y)],[min(x),min(y)])
scatter(x,y)
title('Maximum Distace Achieved')
xlabel('X Values')
ylabel('Y Values')
I'm having two problems with this code: the first is that I somehow need to combine a plot with a scatterplot and the second is that the line in the plot needs to be red while all other points need to be blue. I would try to work with the colors myself but all explanations I've looked up on how to do color for a plot have been rather vague. So if you could help I would greatly appreciate it.

採用された回答

Image Analyst
Image Analyst 2015 年 5 月 5 日
編集済み: Image Analyst 2015 年 5 月 5 日
Get rid of scatter and have two calls to plot
% Plot red lines between the two most separated points.
plot(plot([max(x),max(y)],[min(x),min(y)]), 'r-', 'LineWidth', 2);
hold on
% Plot blue stars at the points.
plot(x, y, 'b*', 'MarkerSize', 10);
grid on;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by