create program using matlab, that displays number of (+) entries (=>0) in matrix and number of negative (<0). Hard code matrix in program. Use nested loops and an if-else-end structure to count (+) and (-) entries. Program should display original matrix and number of positive/negative entries.
Matlab Code:
m=input('Enter number of rows ');
n=input('Enter number of columns');
c=0; d=0;
for i=1:m
for j=1:n
a(i,j)=input('Input elements row wise-\n');
end
end
a=reshape(a,m,n);
for i=1:m
for j=1:n
if a(i,j)>0
c = c+1;
else
d = d+1;
end
end
end
fprintf('Number of +ve entries = %d\n',c)
fprintf('Number of -ve entries = %d\n',d)
Output:
Enter number of rows 2
Enter number of columns2
Input elements row wise-
2
Input elements row wise-
2
Input elements row wise-
3
Input elements row wise-
4
the matrix is:
a =
2 2
3 4
Number of +ve entries = 4
Number of -ve entries = 0
Get Answers For Free
Most questions answered within 1 hours.