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

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

 채택된 답변

Is this what you mean?
A = [1:100;rand(1,100)]; % random example data
B = [1:4;3*rand(1,4)];
plot(A(1,:),A(2,:),'-g',B(1,:),B(2,:),'-r')

댓글 수: 4

Thanks for the response.
I am not sure about understanding this:
A(1,:),A(2,:),
I want to plot
plot(A(:,1),A(:,2),'-g',B(:,1),B(:,2),'-r')
However, I want to plot them as a points rather than lines.
Thanks
I think you may have your indexing backwards. MATLAB uses (row,column) indexing.
However, to plot points instead of lines, change the string inputs that fall after the (x,y) data:
plot(A(:,1),A(:,2),'*g',B(:,1),B(:,2),'*r')
See here for more, and click the "LineSpec" dropdown from the "Input Arguments" list.
Yes, it was my mistake!
Thanks for supporting!
No problem! Glad you got it working.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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:
plot(A(2,:),A(1,:),B(2,:),B(1,:))
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:

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2014년 8월 6일

댓글:

2014년 8월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by