Monday, November 15, 2010

MATLAB-6(FUNCTION FIND)

in this article i want to discuss the function 'find':
find returns the indices of an array elements which have non zero value
just see the following array:
[1 2 0 0 3]
in this the first,second,fifth elements have non zero value so the find function returns 1,2,5.
observe the following code:

x=[1 2 0 0 3];
y=find(x);
disp(y);


this code gives the output 1,2,5.
and observe the following code:

x=[1 2 0 0 3];
[y,z]=find(x);
disp(y);
disp(z);


this code gives the output as
1     1     1
     1     2     5
[y,z]=find(x);
in this line find function gets the rows and columns numbers of the non zero elements of the array x.
observe the following code:

x=[1 2 0 0 3];
[y,z,v]=find(x);
disp(y);
disp(z);
disp(v);


in the above code
[y,z,v]=find(x);
gets the rows and columns numbers of the non zero elements of the array x and v contains the non zero array of x i.e here v contains 1 2 3.
so the output of the above code is
1     1     1
     1     2     5
     1     2     3
we can run the above code in the command window also with or with out using disp.
thats it!

No comments:

Post a Comment