equalizing few matrices size in a cell
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
khaled alsaih
am 4 Mai 2021
Kommentiert: KSSV
am 4 Mai 2021
Hello everyone, and thanks in advance
let's say I have a cell of 10 arrays. but the arrays are not having the same dimensions.
example: 60000x1 , 65478x1, 74578x1 and so on. how can i make all the arrays the same size, knowing that i want the dimensions to have the least size so no zeros padding.
thanks a lot
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 4 Mai 2021
minlen = min(cellfun(@length, YourCell));
truncCell = cellfun(@(C) C(1:minlen), YourCell, 'uniform', 0)
0 Kommentare
Weitere Antworten (1)
KSSV
am 4 Mai 2021
% demo data
C{1} = rand(60000,1) ;
C{2} = rand(65478,1) ;
C{3} = rand(74578,1) ;
% lengths of each cell array
L = cellfun(@length,C) ;
% do interpolation to get the cell array to same size
for i = 1:length(C)
C{i} = interp1((1:L(i))',C{i},linspace(1,L(i),min(L))) ;
end
2 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!