Write a program using a loop to add all the elements of a ma

Write a program using a loop to add all the elements of a matrix producing a scalar. Do not use the MATLAB function sum function or +. For example, [-1 2 3; 4 5 6; -7 8 -9] SUM = 11

Solution

Code:

A=[-1 2 3; 4 5 6;-7,8,-9]
res = 0;
for i=1:size(A,1)
for j=1:size(A,2)
res = res + A(i,j);
end
end

 Write a program using a loop to add all the elements of a matrix producing a scalar. Do not use the MATLAB function sum function or +. For example, [-1 2 3; 4

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site