How to add two vectors or arrays with different length?

4 次查看(过去 30 天)
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

回答(1 个)

Sean de Wolski
Sean de Wolski 2015-4-21
idx = a~=0;
a(idx)+b(idx)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by