Calculate probability of number appearing in a column

9 vues (au cours des 30 derniers jours)
Emma Kuttler le 21 Nov 2019
I have a 1000x296 matrix called Values. The rows represent trials of a simulation, and the rows represent the rank (1-296) of a particular element.
I want to create a matrix that returns the probability of a column having a particular value. I assume i will need a set of nested for loops to count the number of times each value appears in each column, and then divide by the number of rows (1000).
E.g.
The value in cell (1,1) will have the probability of a particular row of column 1 having value 1
The value in cell (1,15) will have the probability of a particular row of column 1 having value 15
The value in cell (200, 155) will have the probability of a particular row of column 200 having value 155.
Thanks!
3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Emma Kuttler le 22 Nov 2019
I'm not looking for the probability distribution, I'm looking for the simple probability of a value appearing in each column.
So more like counting (for example) the number of times the value 1 appears in column 1, dividing by the number of rows, and returning that value in position (1,1). Then counting the number of times 2 appears in column 1, dividing by the number of rows, and returning that in (2,1). Then repeating this for all the columns.
Walter Roberson le 22 Nov 2019
Neither accumarray nor histcounts2 calculate probability distributions. In its simplest form, accumarray just counts.

Connectez-vous pour commenter.

Réponses (2)

Image Analyst le 21 Nov 2019
Just loop over the array getting the histogram in each column.
Something like (untested)
numBins = 25; % Whatever you want.
edges = linspace(0, max(Values(:), numBins);
[rows, columns] = size(Values);
allCounts = zeros(numBins, columns);
for col = 1 : columns
thisColumn = Values(:, col);
counts = histcounts(thisColumns, edges);
allCounts(:, col) = allCounts(:, col) + counts;
end
% Normalize
allCounts = allCounts / sum(allCounts(:));
bar3(allCounts); % Display
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Walter Roberson le 23 Nov 2019
[rowidx, colidx] = ndgrid(1:size(Values,1), 1:size(Values,2));
probs = accumarray([colidx(:), Values(:)],1) ./ size(Values,1);;
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by