How to split a matrix in two halves?
57 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Emanuele Joy
le 17 Mai 2018
Commenté : Emanuele Joy
le 17 Mai 2018
For example, if I have matrix: A = [5, 9, 25, 2, 21, 36];
and I want matrices:
B = [5, 9, 25]; C = [2, 21, 36];
What command do I need to use to split it into two halves? I originally have a matrix of size 1x100001 so I can't manually make two matrices like what I did here lol
0 commentaires
Réponse acceptée
Andrei Bobrov
le 17 Mai 2018
Modifié(e) : Andrei Bobrov
le 17 Mai 2018
n = ceil(numel(A)/2);
B = A(1:n)
C = A(n+1:end);
or
n = ceil(numel(A)/2);
BandC = mat2cell(A(:)',1,[n,numel(A)-n]);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multidimensional Arrays 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!