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 で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!