MATLAB: Element to element sum sum hi i have X = [1 5 7 6 9 2 3 1 4 8 6 5]; and i want to do [1+5 5+7 7+6 6+9 …] how can i do that? thanks Best Answer X(1:end-1)+X(2:end) Related SolutionsMATLAB: How to sum the matrix element Hi Eddy,It is because in one of the for loop, you made sum as a variable too. Using the same variable which is the same as inbuilt function is not encouraged and lead to inappropriate conditions as such. So, update this loop here and this should solve:for i=na:-1:1 sumOut=0; % Replace sum with other variable X(i)=0; for j=1:na sumOut=sumOut+A(i,j)*X(j); end X(i)=(B(i)-sumOut)/A(i,i);endHope this helps.Regards,Sriram MATLAB: Sum I am a little confused, do you mean like this:Y = reshape(1:18,6,3) % A manageable dimension.Y_1 = sum(Y,2)So in your case it would beY_1 = sum(Y,2).';..Or do you mean, more like this:Y = 1:18Y_1 = sum(reshape(Y,3,6))So in your case it would beY_1 = sum(reshape(Y,320,467)) Related QuestionElement-by-element sum of cell arrayElement wise sum in arraySum every n columns, element by elementArray element sum wih conditionElement wise multiplication and sumSum of the element occurence
Best Answer