Plot cell array as a histogram using hist3?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a 30 x 30 cell array and I want to visualize the data in the cell array on a 30 x 30 Bivariate histogram plot using hist3. Each cell in the cell array should represent a grid on the plot & its location on the plot should be the same as its location in the cell array. The data values should be represented on the z axis. Is there any way to achieve this on Matlab?
댓글 수: 0
답변 (1개)
Akira Agata
2017년 6월 14일
You can use bar3 to do this. Here is an example.
% 30x30 cell array sample
C = num2cell(randi(100,30));
% Bivariate histogram
bar3(cell2mat(C));
If you want to change the color of each bar according to its value, please try this.
% Bivariate histogram (color represents each value)
h = bar3(cell2mat(C));
for kk = 1:numel(h)
h(kk).CData = h(kk).ZData;
h(kk).FaceColor = 'interp';
end
댓글 수: 2
Akira Agata
2017년 6월 15일
OK. Then, how about this? The following code generates 24 figures.
% 30x30 cell array sample (some cells have 24x1 numeric array)
C = cell(30);
C{2,2} = randi(100,24,1);
C{4,5} = randi(100,24,1);
for kk1 = 1:24
D = zeros(30);
for kk2 = 1:numel(C)
if isempty(C{kk2})
D(kk2) = 0;
else
D(kk2) = C{kk2}(kk1);
end
end
% Bivariate histogram (color represents each value)
figure
h = bar3(D);
for kk3 = 1:numel(h)
h(kk3).CData = h(kk3).ZData;
h(kk3).FaceColor = 'interp';
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!