How to add two vectors or arrays with different length?

4 views (last 30 days)
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

Answers (1)

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

Categories

Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!