How to combine two vectors? HOW TO SPLIT VECTORS ACCORDING TO INDEX?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aswin Sandirakumaran
am 27 Mai 2018
Bearbeitet: Ameer Hamza
am 27 Mai 2018
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 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 27 Mai 2018
D = B+C;
2 Kommentare
Ameer Hamza
am 27 Mai 2018
Bearbeitet: Ameer Hamza
am 27 Mai 2018
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!