How to have more than one box plot in one plot?

Hey all,
I'm unable to plot more than one box plot in one figure. My data sets are seven n x 1 double (every double array of this seven and I have 7 of them which I want to have boxplots for every 7 data set in one figure, something like this:
Sample data are provided, I have 7 file like this
Thank you all.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 5 日

1 投票

4 件のコメント

BN
BN 2020 年 4 月 5 日
Thank you. I saw this code from you and it's amazing. In the example in the link you used
data = rand(100, 4);
I have different sizes of arrays like this: 27360 x 1 and 28520 x 1 and 29542 x 1; (All have one column and different row numbers). Do you know how I can do in that case? I think I should do this without for loop though I haven't idea how to do this.
Thanks
Ameer Hamza
Ameer Hamza 2020 年 4 月 5 日
This show you an example of how you can do it using cell array
data = {y1,y2,y3,y4,y5,y7,y6}; % y1, y2, y3, ..., y7 are the variables, they can be of unequal length
x = 1:numel(data);
colors = rand(numel(data), 3);
figure();
ax = axes();
hold(ax);
for i=1:numel(data)
boxchart(x(i)*ones(size(data{i})), data{i}, ...
'BoxFaceColor', colors(i,:), ...
'LineWidth', 0.5, ...
'WhiskerLineStyle', '--')
end
BN
BN 2020 年 4 月 5 日
Thank you it's awesome.
Ameer Hamza
Ameer Hamza 2020 年 4 月 5 日
Glad to be of help.

サインインしてコメントする。

その他の回答 (1 件)

Florian Floh
Florian Floh 2020 年 4 月 5 日

1 投票

Concatenating your data into one matrix should do the trick.
Let's say you load two arrays:
load('y.mat');
load('x.mat');
% Concatenate them to a matrix named z
z = [x,y];
% Create a boxplot
boxplot(z);

1 件のコメント

BN
BN 2020 年 4 月 5 日
Thanks but I have different x and y row numbers

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2020a

タグ

質問済み:

BN
2020 年 4 月 5 日

コメント済み:

2020 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by