octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bad mod function - Matlab


From: Vic Norton
Subject: bad mod function - Matlab
Date: Tue, 19 Jun 2018 11:08:20 -0400

The mod function in my Mac system is not working.
———————————————————————————————————

Here is essentially the same script run with Matlab.
This is the way the mod function is supposed to work

%% testmod.m  - test the mod function
%    with Matlab '9.3.0.713579 (R2017b)'

fprintf('-- bad mod function? --\n');
for i = 1 : 11
 fprintf('%4d', i);
 if mod(i, 5) == 1; fprintf('\n'); end
end
fprintf('-- good mod function --\n');
for i = 1 : 11
 fprintf('%4d', i);
 if modxy(i, 5) == 1; fprintf('\n'); end
end

function v = modxy(x, y)  % to replace the faulty mod function
 v = x - y .* floor (x ./ y);
end

%{
>> testmod
-- bad mod function? --
  1
  2   3   4   5   6
  7   8   9  10  11
-- good mod function --
  1
  2   3   4   5   6
  7   8   9  10  11
%}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]