关于数据元素的随机复制

时间:2013-12-02 07:21:44

标签: matlab

请考虑我的示例代码:

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

1 个答案:

答案 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)))