Monday, September 9, 2013

Matlab

write a script that contain following commands:
a matrix A
Q1 Compute average value of element of larger than 2 and smaller than 6
 q2 and replace the element less than 3 by zero


Solution

d=magic(3)
c=0; sum=0;
for i= 1:1:3
for j= 1:1:3
h=d(i,j);
if(h>2 && h<6 )
sum=sum+h;
c=c+1;
end
if(h<3)
d(i,j)=0;
end
end
end
sum
avg=sum/c;
avg
d

No comments:

Post a Comment