% Script Lookin4Stuff
% Using find

clc

% A random array of integers...

x = floor(100*randn(1,10))

% Q. What is the average of the negaive entries?

LessThanZero = x<0      % A boolean vector with ones where x is negative
i = find(LessThanZero)  % indices of the negative entries
s = sum(x(i))           % The sum of the negative entries
n = length(i)           % The number of negative entries
ave = s/n

% More briefly..
i = find(x<0);
ave = sum(x(i))/length(i);

% The long way...
s = 0; n = 0;
for k=1:length(x)
    if x(k)<0
        s = s + x(k);
        n = n + 1;
    end
end
aveTheLongWay = s/n





