How to combine two vectors? HOW TO SPLIT VECTORS ACCORDING TO INDEX?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Aswin Sandirakumaran
il 27 Mag 2018
Modificato: Ameer Hamza
il 27 Mag 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 Commenti
Risposta accettata
Ameer Hamza
il 27 Mag 2018
D = B+C;
2 Commenti
Ameer Hamza
il 27 Mag 2018
Modificato: Ameer Hamza
il 27 Mag 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Operators and Elementary Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!