How to replace cell values with consecutive values related to their index
Show older comments
For example:
a = 1x3 cell array
columns 1 through 3
{1x1} {1x5} {1x3}
I'd like to be able to replace the values in each cell array with consecutive values so that:
a = 1x3 cell array
{[1]} {[2 3 4 5 6]} {[7 8 9]}
Thanks!
Accepted Answer
More Answers (1)
Simpler:
C = {cell(1,1),cell(1,5),cell(1,3)}
N = cellfun(@numel,C);
D = mat2cell(1:sum(N),1,N)
1 Comment
dpb
on 29 May 2021
That's what I intended, but kept muffing the mat2cell syntax...it's always thrown me for a loop for some reason -- rarely ever use it I guess is likely cause.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!