Matlab expanding matrix quickly

3 次查看(过去 30 天)
Hey all,
Suppose you have as input: matrix A = [10 9 8] and some factor X = 3
As output i would like to obtain: R = [10 10 10 9 9 9 8 8 8]
I am wondering if there are better (faster) solutions then my solution below:
R = zeros(1,length(A)*X);
for i =1:X
R(1+length(A)*(i-1):1:length(A)*i) = A(i);
end

采纳的回答

Fangjun Jiang
Fangjun Jiang 2018-8-3
编辑:Fangjun Jiang 2018-8-3
reshape(repmat(A,X,1),1,[])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by