Newbie question - converting a vector into a cellarray of vectors
2 次查看(过去 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!