How to combine two vectors? HOW TO SPLIT VECTORS ACCORDING TO INDEX?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a vector say A = [60,600,15]
I extract any value from this vector A using its index
Eg: If i extract A(2) from A. Then i create a vector B of same length as of A
and place that value in its respective index!
And the left over values will be in vector C = [60,15] OF SAME LENGTH AS A
that is B(2) = 600 and C(1) = 60 and C(3) = 15
*THE FINAL OUTPUT SHOULD BE LIKE B = [0,600,0] AND C = [60,0,15];
NOW USING VECTOR B AND C HOW TO COMBINE THEM TO OBTAIN VECTOR D = [60,600,15]*
CASE 2: IF I EXTRACT A(1) AND A(2)
THEN VECTOR B = [60,600,0] AND THE LEFT OVER VALUE FROM A SHOULD CREATE VECTOR C = [0,0,15]
댓글 수: 0
채택된 답변
Ameer Hamza
2018년 5월 27일
D = B+C;
댓글 수: 2
Ameer Hamza
2018년 5월 27일
편집: Ameer Hamza
2018년 5월 27일
Suppose you define a logical array inB to define which element goes to B
A = [60,600,15];
inB = logical([0 1 0]); %<--- 1 means go to B, 0 mean goes to C
B = zeros(size(A));
B(inB) = A(inB);
C = zeros(size(A));
C(~inB) = A(~inB);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!