Hello,
I've got a 2D matrix of values
nK=10; nM=100; nZ=50;
Cz = rand(nK,nM,nZ);
that I want to histogram with edges
Each element of the Cz has a corresponding probabilty defined in a matrix
p_K_M = rand(nC,nK);
p_K_M = p_K_M/sum(p_K_M,'all');
that is indepent of the variable (z).
I would like a 2D histogram/pdf of the Cz's but would like to avoid looping and masking as in;
P_Cz = zeros(icz,iz);
for iz=1:nZ
thisCz = squeeze(Cz(:,:,iz));
for icz=1:length(CzEdges)-1
hasCorrectCz = ( CzEdges(icz) < thisCz ) & ( thisCz < CzEdges(icz+1) );
if ~any(hasCorrectCz)
continue
end
P_Cz(icz, iz) = sum( p_K_M(hasCorrectCz) );
end
end
Is it possible to use hist3 (I dislike the inputs and I don't think they map well to my variabels as they're constructed), or accumarray to dot times the Cz's with the 2D pdf (p_K_M) or perhaps a generalized histcounts and dot times of a repmatted p_K_M?
I feel like I'm missing a neat function that makes this go from 2 loops to a ~3 liner or something. I really appreciate any tips you have. Please let me know if I've made an error (I "translated" my variables to something easier to parse, but may have done something stupid.)
Cheers,
Michael B.