We have a column vector and a row vector both of same lengths. How to use sum function to get element wise sum of two vectors and final answer display in row vector
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eiman Rana
am 16 Sep. 2021
Kommentiert: Fabio Freschi
am 16 Sep. 2021
I tried sum(vect1,vect2) and a lot of other ways but I cant get the answer. for example vect1 is a column vector that contains even numbers from 200 to 220 and vect2 contains elements 0:0.1:1 ... Following is what I have so far but after Displaying the lengths of both vectors. I am unable to display the elementwise sum of the two vectors (first element in vect1 is added to first element of vect2, second element to the second etc.) in the form of a row vector
vect1 = (200:2:220)';
vect2 = 0:0.1:1;
vect2 = vect2 * 40;
length(vect1)length(vect2);
0 Kommentare
Akzeptierte Antwort
Fabio Freschi
am 16 Sep. 2021
Bearbeitet: Fabio Freschi
am 16 Sep. 2021
vect3 = vect1.'+vect2
If you want to be sure of the element by element sum, regardles the shape of the two vectors (row or column), with the assumptions they are of the same length, you can force them to be column vectors and then transpose the result
vect3 = (vect1(:)+vect2(:)).'
3 Kommentare
Image Analyst
am 16 Sep. 2021
@Eiman Rana can you click the "Accept this answer" link to award Fabio reputation points and to let others know it's solved? Thanks in advance.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!