I have the following problem. Let's say I have four possible values {1 2 3 4}
and I want a specific behavior of mod function
The behavior I seek is this one
1 mod 4 = 1
2 mod 4 = 2
3 mod 4 = 3
4 mod 4 = 4
but I have the following results with matlab.
1 mod 4 = 1
2 mod 4 = 2
3 mod 4 = 3
4 mod 4 = 0
Are there any ideas as how to achieve the desired behavior with the simplest way possible in MATLAB?
If A
holds those values, you can subtract 1, perform mod
and add back 1.
Sample run -
>> A = 1:8
A =
1 2 3 4 5 6 7 8
>> mod(A-1,4)+1
ans =
1 2 3 4 1 2 3 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With