Createing a boxplot from callArrays
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello,
I am struggling with the following problem. I have data with double value in 32 classes a Cell Array. The 32 classes have a different amount of double values. Furthermore, I have the labels for these classes in another CellArray. I want to create a graphic that shows the boxplot of all classes with the correct labels on the x Axis. I found one solution that uses boxplotgroup from file exchange, but this solution didn't work for me. Does anyone have an idea?
댓글 수: 2
Rik
2023년 3월 9일
You should either attach your data or create some example data, and you should show what code you tried, preferably within the editor. If you have a lot of code, you can attach them in an m-file.
Do I understand you correctly that you have a cell array, where each cell contains an array (of type double), and that each cell should become a single box on your boxplot?
You failed to mention your release and whether you have the stats toolbox, so I don't know whether you can actually use the boxplot function, or have access to the boxchart function.
답변 (1개)
Arka
2023년 3월 9일
Hi,
I think this is what you are looking for:
c = arrayfun(@(i){rand(randi([5,20]),1)},1:32);
maxLen = max(cellfun('size', c, 1)); % find max length of datas for all categories, i.e. which category contains the largest amount of data
for i = 1:size(c,2)
c{i} = padarray(c{i}, maxLen-length(c{i}), NaN, 'pre'); % pad the other categories with NaNs
end
c = cell2mat(c); % now we can convert the cell array to matrix, since all rows are of same length
years = compose('%d',1901:1932);
boxplot(c, years);
Since the number of datas in each column was different, you just needed to make them equal so that they can be converted to a matrix.
If you wish to learn more about padarray, please check out the MathWorks documentation page about the same:
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
