% Written by Gun Srijuntongsiri function C=add(A,B) % ADD adds matrix A and B together without using % Matlab's built-in array addition (A+B) % First check for correct dimension if (length(size(A))~= length(size(B))) | any(size(A)~=size(B)) error('The two arrays must have the same dimension.'); end % Then compute the summation entry by entry. for i=1:size(A,1) for j=1:size(A,2) C(i,j) = A(i,j)+B(i,j); end end