overlaying scatter plots on the same graph to control marker color
Show older comments
Hi all,
I am trying to plot data from an excel file. Say I am plotting column 1 vs column 2 but want the marker colors to be blue or red depending on whether the corresponding value in column 3 is 1 or 0. I have written up some code to try to do this but all it does is plot the data with all the markers as blue.
massdata = xlsread('massdata.xlsx');
x = massdata(:,12);
y = massdata(:,15);
gamma = massdata(:,16);
for i = 1:1:32
if gamma(i) == 0
scatter(x, y, 'red');
hold on
end
if gamma(i) == 1
scatter(x, y, 'blue');
hold on
end
end
I am new to matlab so could somebody please let me know what I'm doing wrong? Or if there is an easier/better way to implement conditional marker coloring into a scatter plot.
Thanks very much, Colin
Accepted Answer
More Answers (0)
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!