, , 3 , . . . x , timeit .
function benchie()
% Set up iteration variables
K = 17; n = 4; T = zeros(K,3);
for k = 1:K
x = rand(2^k,1);
% Define the three truncation functions
LuisRound = @() round(x - 0.5/10^n, n);
JodagFix = @() fix(x*10^n)/10^n;
InfoRem = @() x - rem(x,10^-n);
% Time each function
T(k,1) = timeit(LuisRound);
T(k,2) = timeit(JodagFix);
T(k,3) = timeit(InfoRem);
end
% Plot results
figure
plot(2.^(1:K), T); legend('LuisRound', 'JodagFix', 'InfoRem');
grid on; xlabel('number of elements in x'); ylabel('time taken');
end
:

fix, jodag, , - n :
function y = trunc(x, n)
%% Truncate matrix/scalar x to n decimal places
if nargin < 2; n = 0; end; % default to standard fix behaviour if no n given
y = fix(x*10^n)/10^n; % return value truncated to n decimal places
end
:
>> trunc([pi, 10.45, 1.9], 4)
>> ans = [3.1415 10.4500 1.9000]
>> trunc([pi, 10.45, 1.9], 1)
>> ans = [3.1 10.4 1.9]