How can I plot two arrays with different number of columns in one figure with different colours?

3 views (last 30 days)
Hi all,
If I have two arrays:
A (m,2) & B (n,2)
where n and m are the number of columns in each. let say m=100 and n=4. Both arrays have the same number of rows. I want to plot both arrays in the same figure with different colours.
Thank you

Accepted Answer

Evan on 6 Aug 2014
Is this what you mean?
A = [1:100;rand(1,100)]; % random example data
B = [1:4;3*rand(1,4)];

Sign in to comment.

More Answers (1)

Christopher Berry
Christopher Berry on 6 Aug 2014
MATLAB uses (row,column) indexing, so I think you've got it backwards in your examples A and B :)
But, assuming you want to plot row 1 vs row 2 for A and B, ie y vs x or A(1,:) vs A(2,:), then you can use the plot function with both sets of data and MATLAB will assign different colors automatically:
And if you want to plot row 2 vs row 1, just switch the order of arguments in the plot function.
You can also see more plot options and examples here:


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

Translated by