boxplot with descending median

4 ビュー (過去 30 日間)
Jonathan Gingrich
Jonathan Gingrich 2020 年 8 月 26 日
編集済み: Adam Danz 2020 年 8 月 26 日
I am trying to plot my data (8376x35 array with 1x35 cell array of labels) in a 35 box boxplot and order the boxes in descending order based off of the median value of each column. I have seen a lot on ordering by grouping, but I don't believe I am dealing with specific groups as all are part of one group. I started by taking the median of each column , but if I sort that in descending order, I lose the equivalent sorting of the cell array. I tried converting the array to a table with the cell array as the variable names, but could not sort the table by median values of each column. How should I go about sorting my data so that I can plot it as a boxplot in descending order?

採用された回答

Adam Danz
Adam Danz 2020 年 8 月 26 日
編集済み: Adam Danz 2020 年 8 月 26 日
Use the sort index to change the order of columns in your data.
% Create demo data
rng('default')
data = rand(8376, 35).*randi(100,1,35);
% Compute median of each column
med = median(data);
% Sort the columns of data by descending median order
[~, sortIdx] = sort(med,'descend');
dataDescend = data(:,sortIdx);
% Plot the results
boxplot(dataDescend)
If you want to label the orginal column order,
set(gca, 'XTick', 1:numel(med), 'XTickLabel', sortIdx)
xlabel('Original column order')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by