3D Histogram from raw data
81 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to create the a rainflow matrix out of time history of a load data. I can do it easily with the rainflow command but I am trying to learn how I can produce it myself. It is basically a 3D Histogram of three variables ( Mean, Range and Cycle count , random X,Y and Z let's say )
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1386564/image.png)
This is what a rainflow matrix looks like for reference.
For any dataset with X,Y and Z data, I undertand that the first step is to discretize X and Y . What I do not understand is how I can allot the Z value to each bins and ultimately plot something like this.
0 Kommentare
Antworten (1)
Mathieu NOE
am 17 Mai 2023
hello
see example below - this is equivalent to hist3
% dummy data (col vectors)
x = rand(100,1);
y = rand(100,1);
z = rand(100,1);
%% bin the data (Hist3 clone)
nBins = 10; %number of bins (there will be nBins + 1 edges)
XEdge = linspace(min(x),max(x),nBins+1);
YEdge = linspace(min(y),max(y),nBins+1);
[~, xBin] = histc(x, XEdge);
[~, yBin] = histc(y, YEdge);
% count number of elements per (x,y) pair
[xIdx, yIdx] = meshgrid(1:nBins, 1:nBins);
xyPairs = [xIdx(:), yIdx(:)];
Z = zeros(size(xyPairs,1),1);
for i = 1:size(xyPairs,1)
Z(i) = sum(ismember([xBin, yBin], xyPairs(i,:), 'rows'));
end
% Reshape nPerBin to grid size
Z = reshape(Z, [nBins, nBins]);
% plot data
figure(1)
b = bar3(Z);
% change bar color to match Z value
for k = 1:length(b)
zdata = b(k).ZData;
b(k).CData = zdata;
b(k).FaceColor = 'interp';
end
colorbar('vert');
% Change colormap
colormap jet
% Label the axes
xlabel('x')
ylabel('y')
title('hist3 simulation');
2 Kommentare
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!