How to split a matrix in two halves?
52 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Andrei Bobrov
2018-5-17
编辑:Andrei Bobrov
2018-5-17
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]);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!