How to replace cell values with consecutive values related to their index
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (1)
Simpler:
C = {cell(1,1),cell(1,5),cell(1,3)}
N = cellfun(@numel,C);
D = mat2cell(1:sum(N),1,N)
1 commentaire
dpb
le 29 Mai 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.
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!