% tfind Demonstrates use of find [PHYS210-DEMO]

% If v is a vector, then find(v) returns the indices corresponding to 
% the non-zero entries in the vector.

% Generate a vector of 100 integers chosen randomly from 1 to 10 
% inclusive.
vrand = randi(10, 1, 100)

% This statement generates a vector whose elements are 1 / 0 if the 
% corresponding elements of vrand are equal-to-5 / not-equal-to-5 
% respectively.
vrand5 = (vrand == 5)

% This statement returns the indices corresponding to the non-zero 
% entries in vrand5, and consequently those indices k for which
% vrand(k) == 5.
ivrand5 = find(vrand5)

% Thus, the following will generate a vector whose elements are all
% 5.
v5 = vrand(ivrand5)

% Perhaps more interestingly, generate the vector of values from
% vrand which are NOT equal to 5.

vnot5 = vrand(find(vrand ~= 5))
