作者celestialgod (天)
看板MATLAB
标题Re: [问题] 关於统计机率问题
时间Tue Aug 25 22:56:23 2015
※ 引述《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://webptt.com/cn.aspx?n=bbs/MATLAB/M.1440514588.A.61B.html
※ 编辑: celestialgod (123.205.27.107), 08/25/2015 22:59:12