%% to evaluate the for loop time with memory allocation first
StartTime = cputime;
Res = zeros(Length, 1);
for i=1ength
??? Res(i) = Source(i) >= 0;
end
EndTime = cputime;
Duration = EndTime - StartTime;
disp(['The for loop with memory allocation running time is ' num2str(Duration)]);
%% to evaluate the for loop time with memory allocation first
%? with if else clause
StartTime = cputime;
Res = zeros(Length, 1);
for i=1ength
??? if Source(i) >= 0
??????? Res(i) = 1;
??? else
??????? Res(i) = 0;
??? end
end
EndTime = cputime;
Duration = EndTime - StartTime;
disp(['The for loop with memory allocation running time' ...
??? 'with if clause is ' num2str(Duration)]);
%% to evaluate the array operation running time
StartTime = cputime;
Res = Source >= 0;
EndTime = cputime;
Duration = EndTime - StartTime;
disp(['The array operation time is ' num2str(Duration)]);