%
% A06B.m 
%
% This program is exactly the same as A06A.m except that the array y is
% first preallocated (see line 21)
%
% Matlab-Monkey.com
% 12/30/2014

% tidy-up your workspace
clc         % clear command window
clear       % clear all variables
close all   % close all graphics windows


N = 1e8;            % set the number of point to 10^8

tic;                % start timer to measure computation time

y = zeros(1,N);     % ***** Added this statement to pre-allocate y array

i = 0;              % initialize counter
                    
for t = linspace(0,2*pi,N)   % start of for loop
    i = i + 1;      % increment counter
    y(i) = sin(t);  % evaluate sin(t)
end                 % end of for loop

tElapsed = toc;     % measure elapsed time since timer started

% display elapsed time to command window
fprintf('elapsed time = %.3g seconds\n',tElapsed);
