Re: [問題] 關於統計機率問題
※ 引述《sunnycello (cello)》之銘言:
: 手上有32*32的cell
: 每個cell都有一個矩陣跟一個字串
: 矩陣內兩個值為一組
: 32*32個中同組會重複出現
: 想用huffmandict在cell上
: 現在只需要出現的機率
: 不過要知道每個矩陣內可能重複的矩陣機率
: 構想是用兩個for去寫
: 不過算各個矩陣出現的機率就卡住了
: 字串是32*32個是的固定
: 不過其他的矩陣機率個數變很複雜
我生成一個4*4的cell,每一個cell以struct方式存一個字串跟一個矩陣
(根據你敘述字串沒用到,我就不隨機生成字串了)
根據前面一篇的討論(#1LmpSLQh (MATLAB)),我們可以用下面的方式做計算次數的動作
dat = reshape(arrayfun(@(x) struct('str', 'a', 'mat', ...
randi(6, randi(20, 1, 1), 2)), 1:16, ...
'UniformOutput', false), [4, 4]);
uniqueMats = cell(size(dat)); % 相異的各組
freq = cell(size(dat)); % 各組出現次數
for i = 1:numel(dat)
[uniqueMats{i},~,uniqueRowsIndices] = unique(dat{i}.mat, 'rows');
freq{i}=histc(uniqueRowsIndices,unique(uniqueRowsIndices));
end
count = cellfun(@length, freq); % 你要的相異組數
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.27.107
※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1440514588.A.61B.html
※ 編輯: celestialgod (123.205.27.107), 08/25/2015 22:59:12
討論串 (同標題文章)
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章