mk_ndxb.m

来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 26 行

M
26
字号
function ndx = mk_ndxB(bigdom, smalldom, ns)
% MK_NDXB Compute mapping from small table to big table
% ndx = mk_ndxB(bigdom, smalldom, ns)
%
% Example: bigdom = [a b c d], smalldom = [b c], then ndx([a b c d]) = [b c]
% so we can implement multiply_by_table as
% for i=1:prod(ns(bigdom))
%   big(i) = big(i) * small(ndx(i))
% end
% or big = big .* small(ndx)


mask = find_equiv_posns(smalldom, bigdom);
N = prod(ns(bigdom));
subs = ind2subv(ns(bigdom), 1:N);
ndx = subv2ind(ns(smalldom), subs(:,mask));

if isempty(smalldom)
   ndx = 0;
else
   S = prod(ns(smalldom));
   D = N / S;
   ndx = reshape(ndx-1, S, D);
end
ndx = int32(ndx);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?