Newbie question - converting a vector into a cellarray of vectors
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a vector X and want a cell array C containing N copies of that vector. How do I do that?
Here is how I am doing it now:
X = 1:5; N = 3;
C = mat2cell( repmat( X, N, 1 ), ones( N, 1 ), size( X, 2 ) );
This just feels like something that should be a primitive - converting back & frth betweenmatrices and cellarrays in different ways.
댓글 수: 0
채택된 답변
추가 답변 (1개)
Jan
2011년 7월 8일
More efficient, because shared data copies are created:
C = cell(N, 1);
C(:) = {X};
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!