Plot cell array as a histogram using hist3?
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Akira Agata
on 14 Jun 2017
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 Comments
Akira Agata
on 15 Jun 2017
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
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!