将 python 'repeat' 代码转换为 Matlab

converting python 'repeat' code to Matlab

我正在尝试将以下 python 代码转换为 Matlab,但是,我找不到与 repeat 等效的代码。我试过“repmat”但没有得到相同的结果。 k.size 是 64 和 LL 是一个 10 * 10 矩阵。

Id = (2 * LL).repeat(K.size).reshape(-1, 8, 8)

此外,如何在 matlab 中将 (2 * LL).repeat(K.size) 转换为 (-1,8,8) 的形状。

您可以执行以下操作。

k_size = 64;                % specify K.size
m = 8; n = 8;               % specify dimensions of each Id slice
LL = reshape(1:100,[],10);  % specify matrix LL

M = 2*LL.';                 %
Id = reshape(repmat(M(:),k_size,1),[],m,n);

如果你想要等同于重复,你可以执行以下操作。

function v = repeat(M,k)

Mt = M.';
A = repmat(Mt(:),k).';
v = A(:);

end