how to plot boxplot of two matrix

I have two matrix with different sizes:
A (13*5)
B (9*5)
I want to plot each cloumn of A next to similar coulmn of B, but with diferent color. (i.e. I should have 10 box within my boxplot plot)
Roxan

답변 (1개)

the cyclist
the cyclist 2020년 8월 15일

1 개 추천

There are likely a few different ways to do this task. Here is one straightforward way:
A = rand(13,5);
B = rand(9,5);
xc = 1:5;
offset = 0.1;
w = 0.1;
figure
hold on
boxplot(A,'Positions',xc-offset,'Widths',w,'Colors','r');
boxplot(B,'Positions',xc+offset,'Widths',w,'Colors','k');
The documentation for boxplot explains most of what I have done here. Check out the documentation for the hold command, too, if you are unfamiliar with that.

댓글 수: 4

Roxan
Roxan 2020년 8월 15일
Thanks for your reply. I know this approch, but the problem would be that if the min/max value of the two matrix are diferent from eachother, the axis has to be adjusted later. I am thinking of combing these two matrix into one!
the cyclist
the cyclist 2020년 8월 15일
I guess I didn't appreciate what you meant by "similar" columns. I think I would handle this by manipulating the data ahead of the plotting. You need to define a specific metric for similarity, and then sort by that.
If you combine the matrices into one, you might have a more difficult time specifying the colors of the two different matrices.
It might be easier to help if you uploaded some real data.
Roxan
Roxan 2020년 8월 17일
what will happen if the number of clumn and rows are not similar in both matrix? lets say:
A=9*16
B=13*17
I would like to have the boxplot of this two matrix on the same figure!
the cyclist
the cyclist 2020년 8월 17일
The solution I posted can be very easily changed to the case where the matrices are different sizes, but you didn't seem to like that solution, so I won't post that.
Especially when the data are different sizes, how do you want to decide which columns should be near each other?
You need to add more detail about what you want. You are leaving us to guess too much.

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

카테고리

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

태그

질문:

2020년 8월 15일

댓글:

2020년 8월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by