Filter löschen
Filter löschen

How to add two vectors or arrays with different length?

4 Ansichten (letzte 30 Tage)
mahmoud el majzoub
mahmoud el majzoub am 21 Apr. 2015
Beantwortet: Sean de Wolski am 21 Apr. 2015
Dear all , Anyone could help to substract or add two vectors ith different length.For instance , if i have these to vectors
a=[1 2 0 3 0 4 ] with six elements b=[1 2 3 4 5 6 7 8 9] with 9 elements. My question as follow: .First ,i have to make the a-vectors by skipping all zeros values as new a=[1 2 3 4].
.Then , i have to add the new vector of a with b exactly each element in a to each element of b, and the zeros element of a should not be inculded for the assigned values in b.The results should be as anew = [ 1 2 3 4 ] bnew= [1 2 4 6 ] anew+bnew =[2 4 7 10] Please if you can help me as soon as possible. Regards mah

Antworten (1)

Sean de Wolski
Sean de Wolski am 21 Apr. 2015
idx = a~=0;
a(idx)+b(idx)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by