Plot cell array as a histogram using hist3?
1 次查看(过去 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!