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?

回答(1 个)

Akira Agata
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 个评论
Atiqah Zakirah
Atiqah Zakirah 2017-6-15
Thank you for the reply! However, I received this error "Dimensions of matrices being concatenated are not consistent". The images attached are a snippet of my 30 x 30 cell array and the values in each cell. Each cell holds 24 values and all cells hold different values from each other. I want to plot the each row value of each cell on a 3D histogram. That means I should have a total of 24 graphs. Can bar3 still be used to achieve this?
Akira Agata
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 CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by