请考虑我的示例代码:
data=[-1 0 1 2]; % data
N=[4,8,16]; % No. of desired output columns
现在创建一个输出矩阵,以便:
out=1xN % having each element of data randomly repeated exactly N/4 times
答案 0 :(得分:1)
对于N作为标量,它很简单:
data=[-1 0 1 2];
N= 4
R = repmat(data', 1, N); %// You actually you don't really need the '
R(randperm(numel(R)))