How to replace cell values with consecutive values related to their index
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (1)
Simpler:
C = {cell(1,1),cell(1,5),cell(1,3)}
N = cellfun(@numel,C);
D = mat2cell(1:sum(N),1,N)
1 Commento
dpb
il 29 Mag 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.
Categorie
Scopri di più su Matrices and Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!