Summation of even and odd element of matrix using MATLAB
clc;
m=input('ROW=');
n=input('Cloumn=');
x=randi([2,5],m,n)
Evensum=0;
oddsum=0;
for i=1:1:m
for j=1:1:n
r=i+j;
if mod(r,2)==0
p=x(i,j);
Evensum=Evensum+p;
else
q=x(i,j);
oddsum=oddsum+q;
end
end
end
Evensum
oddsum
No comments:
Post a Comment