Write
a script program to display the number of distinct elements in a matrix?
n=input('Enter
number of rows you want in matrix:\n');
m=input('Enter
number of columns you want in the matrix:\n');
a=input('Enter
a matrix:');
r=1;
c=1;
count=0;
b=reshape(a,1,n*m);
while
c<m*n
if b(1,c)~=b(1,c+1)
count=count+1;
end
c=c+1;
end
disp(count);
OUTPUT
Enter
number of rows you want in matrix:
2
Enter
number of columns you want in the matrix:
3
Enter
a matrix:[1,1,2;3,4,5]
5
No comments:
Post a Comment