How to create a cell array by repeating a row vector
이전 댓글 표시
I have a row vector A=[1:10]; I want to create cell array CA= cell(1,10) , where CA(1,1)= [A(1) A(1);A(1) A(1)], CA(1,2)=[A(2) A(2);A(2) A(2)]... so on and so forth. I understand that this oprtation can be done using a for loop. However, is there a way of doing this using cell array indexing, or some other faster method than a for loop ?
답변 (1개)
A = 1:10 ;
B = reshape(repelem(A,4,1),2,2,10) ;
C = num2cell(B,[1 2]) ;
celldisp(C)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!