How to create a cell array identical in size, but containing cell position in each cell?
3 次查看(过去 30 天)
显示 更早的评论
I have a cell array, with different number of elements in each cell. I convert the cells to a 1xn matrix with
For example,
A = {[1,2,3,4]; [1,2,5]; [5,6,1,2,4]; [44]}
I want to create a new cell array which is identical in size to A containing cell number as element sof each of the cell such that the output would look like -
B = {[1,1,1,1,]; [2,2,2]; [3,3,3,3,3]; [4]}
How can I make this?
0 个评论
采纳的回答
G A
2021-12-1
A = {[1,2,3,4]; [1,2,5]; [5,6,1,2,4]; [44]}
B = cell(size(A));
for k = 1:length(A)
B{k} = repmat(k,1,length(A{k}));
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!