[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bad mod function
From: |
Vic Norton |
Subject: |
Re: bad mod function |
Date: |
Tue, 19 Jun 2018 13:07:24 -0400 |
> On Jun 19, 2018, at 12:36 PM, Rik <address@hidden> wrote:
>
> For the moment, skip the for loop and more complicated code. What does the
> following return when entered on the Octave command line?
>
> mod (5,5)
> mod (6,5)
> mod (7,5)
>
> It should be 0, 1, and 2 respectively. If it isn't then there is something
> wrong with the installation as Dmitri suggested.
>
> --Rik
Everything works the way it should.
octave> mod(5,5)
ans = 0
octave> mod(6,5)
ans = 1
octave> mod(7,5)
ans = 2
octave> mod(5,5) == 1
ans = 0
octave> mod(6,5) == 1
ans = 1
octave> mod(7,5) == 1
ans = 0
Now I’ll just enter the loop code:
octave> for i = 1 : 11
> fprintf('%4d', i);
> if mod(i, 5) == 1; fprintf('\n'); end
> end
1
2 3 4 5 6
7 8 9 10 11
Very strange! Now everything works the way it should. There must be gremlins in
my computer! And my original code that inspired all this works correctly as
well. Apparently I just needed to restart Octave or the computer.
Regards,
Vic