Split vector into 2 variables
조회 수: 13 (최근 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!