% this is a script file to demonstrate conditions and selecting elements
Exa = 2;  % choose the example to run

switch Exa
  case 1                  % selecting
    x = rand(1,10);       % create 10 random numbers with uniform distribution
    ans1 = x < 0.5        % indicate the elements larger than 0.5
    ans2 = find(x<0.5)    % return indicies of elements satisfying the condition
  case 2
    n = 1000000;
    x = randn(n,1);       % create the random numbers
    time0 = cputime();    % use a for loop with an if condition
    counter = 0;
    for i = 1:n
      if abs(x(i))<1 counter = counter+1; end%if
    end%for
    percentage1 = counter/n
    time1 = cputime-time0
    time0 = cputime();
    percentage2 = sum( abs(x)<1 )/n
    time2 = cputime-time0
end%switch
