3D Histgram plot for [N,M] Matrix, visualize result monte carlo simulation

1 visualización (últimos 30 días)
Dear all,
I have a question about the visualization of a matrix created by the use of a monte carlo analysis.
With the use of a monte carlo analysis for different cases ( different angle of the cone of a structure) a Matrix of 31*1000 has been created. For this example 1000 times the calculation result of the monte carlo simulation. And 31 times a different angle of the cone, 30 degrees till 60 degrees.
Now i would like to create a 3D histogram to visualize the results compared to eachother. For now i have: A=[31,1000] hist(A(1,:),30)
Which result in the histogram i like, the results of the monte carlo nicely stored in 30 bars. but only for angle 1 (30 deg).
I would like a z-axis (3D) to visualize the other angles of the histogram. Kind of a surf(A) commmand but then histograms. The hist3(A) command doesnt give the pleased result (only 2 columns possible) but gives an indication of how i would like my histgram 3D visualization.
I hope i'm clear enough. Can anyone help me with this one?

Respuesta aceptada

arich82
arich82 el 11 de Dic. de 2015
It seems like you just want a histogram for each of the 30 cases. If so, this is done very simply using histc and bar3 (essentially just two lines of code; three if you don't use the default edges):
rng(0);
% make dummy data
ncases = 30;
N = 1000;
data = NaN(ncases, N);
for k = 1:ncases
% generate a dummy random-normal distribution
% with random mean and random standard deviation
data(k, :) = rand(1) + rand(1)*randn(N, 1);
end
% generate data for histograms: 1 histogram per column
edges = [-5:0.5:5]; % bin edges
counts = histc(data, edges, 2); % specify dim 2 to act column-wise
% plot results
hf = figure;
ha = axes;
hb = bar3(edges, counts.'); % note the transpose to get the colors right
xlabel('case number')
ylabel('bins');
zlabel('count');
Please accept this answer if it helps, or let me know in the comments if I've missed something.
  1 comentario
Niels van Dijk
Niels van Dijk el 13 de Dic. de 2015
Dear Arich82,
The visualization of this example is exactly what i'm looking for!
Unfortunately i can't manage to implement your guidelines correctly.
What am i doing wrong in my code? The input value is Fh_u, this is a matrix of 31*100000 Where 31 are the cone angles. And 100000 the number of simulations.
The code for the plot i have now is as follows:
figure (4)
bx1 = subplot(2,2,1);
edges = [1500000:2000000:2500000]; I dont know if correctly stated now, values of the simulation vary from 1.5 - 2.5 *10^6 Newton._
counts = histc(Fh_u,edges);
bar3(edges,counts);
grid on;
grid minor;
h = findobj(gca,'Type','patch');
h.FaceColor = [0 0.5 0.5];
h.EdgeColor = 'w';
title('Upward bending - F_h')
zlabel('Count')
ylabel('Newton')
xlabel('Angle of Cone')

Iniciar sesión para comentar.

Más respuestas (1)

Mike Garrity
Mike Garrity el 10 de Dic. de 2015
Is histogram2 what you're looking for?
  3 comentarios
A Lotgering
A Lotgering el 11 de Dic. de 2015
Editada: A Lotgering el 11 de Dic. de 2015
Hi Mike Garrity, thanks again for your quick reply! I'm Alex his team mate for this assignment. I think we have to give some additional information because I think the histogram2 plot is not the one we are looking for.
We like to plot a 2D histogram from a 30 by N matrix. In this matrix data from a Monte Carlo analysis is stored for 30 different cases. The data stored in de N colums can be used for the 2D histogram plot. However, we like to plot the histograms of every case into one single '3D' plot.
If you take axis x,y,z. Horizontal x-axis is for the data stored in the N columns. vertical y-axis is for the frequency of those values to create a histogram (we call this 2D). Horizontal z-axis is for the 30 different cases for which we like to create a similar histogram in de x and y-axis.
Is this even possible with histograms or should we use a different plot style?
Mike Garrity
Mike Garrity el 11 de Dic. de 2015
Editada: Mike Garrity el 11 de Dic. de 2015
I'm not quite sure I'm following. Do you mean something like this?
% Generate some fake data
npts = 1000;
data = zeros(30,npts);
for i=1:30
data(i,:) = rand(1)*(randn(1,npts)-1) + rand(1)*(randn(1,npts)+1);
end
If so, the bad news is that I ran into a number of bugs trying to create this. The histogram object wasn't really happy with what I was trying to do to it. Here's what I came up with, but it's kind of lame.
% Create 30 histograms and rotate them into place
max_val = 0;
for i=1:30
g = hgtransform('Matrix',makehgtform('translate',[0 i 0], ...
'xrotate',pi/2));
if i==1
hold on
end
h = histogram(data(i,:),'BinWidth',.2,'FaceAlpha',1);
h.Parent = g;
max_val = max(max_val,max(h.Values));
end
% Setup axes correctly
set(gca,'SortMethod','depth')
xlim([-pi pi])
ylim([1 30])
zlim([0 max_val])
view(3)
xlabel('Value')
ylabel('Series')
zlabel('Probability')
box on
It might make more sense to use histcounts with bar3 or waterfall if this is the sort of thing you're after.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by