Split vector into 2 variables
9 次查看(过去 30 天)
显示 更早的评论
I specifically want to use length and fix to split a vector (of an even or odd number) into two halves and then assign each half a variable.
0 个评论
采纳的回答
Stephen23
2015-1-28
编辑:Stephen23
2015-1-28
Something like this?:
>> A = [101,102,103,104,105];
>> X = 1:numel(A) < 4;
>> B = A(X)
B =
101 102 103
>> C = A(~X)
C =
104 105
2 个评论
Stephen23
2015-1-31
编辑:Stephen23
2015-2-7
You can adjust the compared value to anything you would like to, including half the vector length. This will work for vectors of any length:
>> A = [101,102,103,104,105];
>> X = 1:numel(A) < numel(A)/2;
>> B = A(X)
B =
101 102
>> C = A(~X)
C =
103 104 105
This will automatically adjust to any length of vector A. Note that if the vector A has an odd number of elements, then C will have one more element than than B.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!