How can I plot 2 different matrix with different color at the same figure via scatter function?

3 views (last 30 days)
Hello,
Firstly, I'm new here and matlab. I've been trying to plotting 2 different matrix at the same figure. I have a 400*2 matrix; first column is expressing different matrix and second column is different matrix as well. Shortly,
dataset = xlsread('data.xlsx','Sheet1'); %loading data from excel table
plot(dataset(:,1),dataset(:,2), 'o-r', '*-g');
hold on
My goal is shortly showing the first matrix on the x- axis and showing second matrix on the y- axis at the same figure and each matrix will have unique color. Like a above figure. But I'm having an error. Can you help me please?

Answers (1)

dpb
dpb on 20 Feb 2017
Well, to have something like the above figure you'd need two sets of x-y data, not just one list of two columns as you indicate. Oh, unless the two columns you're talking about above were to be cell array columns, but that doesn't jibe with xlsread that will return an "ordinary" array of doubles.
So, don't know where you're going to have the data sufficient to generate the plot shown.
But, given that you do have that, it's pretty simple albeit scatter doesn't handle arrays so you have to do it in two separate calls unlike plot
scatter(x1,y1,25,'r','*')
hold all
scatter(x1,y1,25,'b','+')
NB: the "trick" in ML HG to add stuff onto an axes after the first plot or line or whatever high-level function is to use hold on or hold all to keep the second call from clearing the previous data from the axes. See the documentation for more details and examples.

Categories

Find more on Discrete Data 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!