extracting the median of a boxplot

39 ビュー (過去 30 日間)
zahra zol
zahra zol 2017 年 4 月 15 日
編集済み: Songbai Ji 2021 年 6 月 10 日
hie. i have 6 boxplot figures like what i have attached to this post. all i want is to extract the median values of each box in the first subplot of each figure. can anybody help pls?

採用された回答

Star Strider
Star Strider 2017 年 4 月 15 日
From the documentation:
  • boxplot creates a visual representation of the data, but does not return numeric values. To calculate the relevant summary statistics for the sample data, use the following functions: {In the documentation, the function list follows}
So, to get the median of the first box in a particular plot, do something like this:
Data = randn(100, 10);
Median_1 = median(Data(:,1));
figure(1)
boxplot(Data);
grid
  3 件のコメント
Star Strider
Star Strider 2017 年 4 月 15 日
My pleasure.
I did my best to use findobj to get the median (as the documentation for boxplot suggests), but I could not make it work. Apparently it is only possible to use findobj to change specific properties of boxplot.
Songbai Ji
Songbai Ji 2021 年 6 月 10 日
編集済み: Songbai Ji 2021 年 6 月 10 日
Actually, boxplot returns a list of handles that you can ues to retreive the data:
t = rand(100,1);
hd = boxplot(t);
Now hd is a 7-by-1 array. You can check:
get(hd(1))
etc. to see what data it provides -- check the "tag" field. There should be one that gives median (use 'ydata').
I think boxplot will be able to remove outliers. Directly getting median from data does not.
You can also use findobj to retreive the handle:
hd = findobj('tag', 'Median');
then:
get(hd)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by