group every ten cell array
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
pasta pontikaki
le 18 Mai 2019
Modifié(e) : pasta pontikaki
le 20 Mai 2019
Hi all i have a cell array 1x180 and i want to group by every 10 cells
For example i want the elements from 1 cell till 10 get grouped,11:21, 22:32 etc..
So the new cell should be 1x18
How can i do this?
0 commentaires
Réponse acceptée
Adam Danz
le 18 Mai 2019
Modifié(e) : Adam Danz
le 18 Mai 2019
c = cell(1,180); % the original 1x180 cell array
newCell = mat2cell(c,1,repmat(10,1,18)); %the new nested cell array
5 commentaires
Adam Danz
le 19 Mai 2019
Modifié(e) : Adam Danz
le 19 Mai 2019
Yeah, you can still concatenate them vertically but you'd need to pad the shorter vectors. Here are both methods:
Concatenate horizontally
newCellMerge = cellfun(@(x)[x{:}],newCell, 'UniformOutput', false);
Concatenate vertically, pad with NaN values at the end of short vectors
newCellMerge = cell(size(newCell));
for i = 1:length(newCell)
len = cellfun(@length, newCell{i});
cellPad = cellfun(@(x,y)padarray(x',y,NaN,'post')',newCell{i}, num2cell(max(len)-len),'UniformOutput',false)';
newCellMerge{i} = cell2mat(cellPad);
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!