# How to implement modulo to the code

1 view (last 30 days)
SugerCodeCude on 4 Jul 2019
Commented: SugerCodeCude on 5 Jul 2019
for i = 1:N
if (TFx(i) == 0) && (TFy(i) == 0)
if (sOnAngleH0(i)>=xBotEdge && sOnAngleH0(i)<=xTopEdge...
&& AngleHa(i)>=yBotEdge && AngleHa(i)<=yTopEdge)
xi = ceil((sOnAngleH0(i)-xBotEdge)/[(xTopEdge - xBotEdge)/row]);
yj = ceil((AngleHa(i)-yBotEdge)/[(yTopEdge - yBotEdge)/col]);
%%Would the mod go here and if yes how to set up mod()
bins0to120(xi, yj) = bins0to120(xi, yj) + 1;
end
end
end
The code does the following:
xBotEdge = 0
xTopEdge = 360
yBotEdge = 0
yTopEdge = 360
and row and col are 10.
with Matlab I am having a hard time to implement modulos
To three bins that is:
bin0to120
bin120to240
bin240to360
the data will be in their respectfull bins?
Thank you for any help
SugerCodeCude on 5 Jul 2019
Yash Totla, thank you for the doc link, I have been in the dark alleyway and hoping that someone who could help to shine light on my struggle with the mod.
with the code above I have then it this way,
having three of the same code only I changed the parameters to put the data in the bins as need. It made the code in to a more of a if elseif statement, I know that mod can help to cut the code down.

Guillaume on 5 Jul 2019
It looks like what you are trying to do is build the histogram of the two variables sOnAngleH0 and AngleHa. This is easily done with histcounts2 and has nothing to do with modulo operations.
binned = histcounts2(SonAngleHo, AngleHa, 0:120:360, 0:120:360)
As Walter said, your bins are not properly defined. The first bin in the above will include 0 but not 120 (which is part of the 2nd bin). The last bin includes both 240 and 360.
SugerCodeCude on 5 Jul 2019
Thank you, this too helps histcount2. I will contiune to look into this.
Thank you again all!!