Matlab - 相当于 R 的 rep() 与时间参数

Matlab - equivalent of R's rep() with times argument

我想知道在 Matlab 中实现的最快方法是什么,在 R 中我将使用带有 times 参数的 rep() 函数实现什么,例如

v1=1:5;v2=5:1;out=rep(v1,times=v2);out
# 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

即将向量 v1 中的每个元素复制到向量 v2 中相应元素指定的次数。有什么想法吗?

您可以使用repmatrepelems,例如

 z = repelems(x,[1:4;rep])