Combining two plots and adding color to points
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Image Analyst
on 5 May 2015
Edited: Image Analyst
on 5 May 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!