Using Size and cell functions to split a matrix
2 次查看(过去 30 天)
显示 更早的评论
I need help writing a function, that splits matrix X into two halves. X1 is the left half of X and X2 is the right half of X. In the case that there is an odd number of columns, the middle column should go to X1.
0 个评论
采纳的回答
Star Strider
2014-9-10
This works:
X = randi(20, 5, 9);
[Xrw, Xcl] = size(X);
Odd = rem(Xcl,2);
Xs = mat2cell(X, Xrw, [fix(Xcl/2)+Odd fix(Xcl/2)]);
X1 = Xs{1}
X2 = Xs{2}
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!