How to split data into multiple "chunks"?
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Is there an algorithm to split a dataset of a few thousand points into multiple "chunks" of length 'n'?
0 commentaires
Réponses (2)
KSSV
le 15 Oct 2020
Modifié(e) : KSSV
le 15 Oct 2020
Read about reshape.
A = rand(1,1000) ;
n = 100 ;
iwant = reshape(A,100,[]) ;
size(iwant)
iwant(:,1) % 10 columns of 100 rows
1 commentaire
Xuan Gip
le 27 Juin 2023
is there any way to reshape based on a pattern? For example, I have a data that goes 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 and I want the reshape the entire data set to start from that first "1" to the last "1" on the second group of 1s.
Ameer Hamza
le 15 Oct 2020
Another approach is to create a cell array.
M = rand(1, 1000);
n = 100;
C = mat2cell(M, 1, n*ones(numel(M)/n, 1))
3 commentaires
Ameer Hamza
le 16 Oct 2020
Your number of elements in vector M must be a multiple of 'n'. If it is something else, you will get that error.
KSSV
le 16 Oct 2020
- Try to make M divisble by n, by appending NaN's to your array.
- Or make first few chunks of same size and leave last chunk with reduced elements
Voir également
Catégories
En savoir plus sur Logical 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!