Calculate probability of number appearing in a column
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2019 年 11 月 22 日
Neither accumarray nor histcounts2 calculate probability distributions. In its simplest form, accumarray just counts.
回答 (2 件)
Image Analyst
2019 年 11 月 21 日
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 件のコメント
Walter Roberson
2019 年 11 月 23 日
[rowidx, colidx] = ndgrid(1:size(Values,1), 1:size(Values,2));
probs = accumarray([colidx(:), Values(:)],1) ./ size(Values,1);;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!