How to add data of 2 vectors with different size
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jamais avenir
am 18 Apr. 2015
Kommentiert: Star Strider
am 18 Apr. 2015
Hi
I have 2 vectors and I want to merge them directly. A=[1;2;3;4;5] and B=zeros(17,1) where, elements of A are going to these indices [4 5 7 11 13];
A_new=[0;0;0;1;2;0;3;0;0;0;4;0;5;0;0;0;0]
0 Kommentare
Akzeptierte Antwort
Star Strider
am 18 Apr. 2015
One way:
B = zeros(17,1);
A = [1;2;3;4;5];
I = [4 5 7 11 13];
A_new = B;
A_new(I) = A;
2 Kommentare
Star Strider
am 18 Apr. 2015
That isn’t the same as in your original Question.
You have to address them by the appropriate subscripts, and it works:
aa = [1 2 3 4];
bb = [100 100];
cc = aa;
cc(1:2) = cc(1:2) + bb;
There may be other ways, but that’s the most efficient.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!