How to implement modulo to the code

1 visualización (últimos 30 días)
SugerCodeCude
SugerCodeCude el 4 de Jul. de 2019
Comentada: SugerCodeCude el 5 de Jul. de 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
  4 comentarios
SugerCodeCude
SugerCodeCude el 5 de Jul. de 2019
Editada: SugerCodeCude el 5 de Jul. de 2019
Walter, yes sorry to indicate that the bins overlap when at 120, I will adjust it in the if statment.
I know if I get the mod to work, then I can indicate it there to put it in its respectful bin.
when the data is coming in to the bins which are divided in between 0 < angle < 360, first bins are 0 < angle < 120, 120 < angle < 240 and 240 < angle 360. I understnad I am overlaping as I am write logic but I am using the ceil to put the data in the correct as ceil does.
I hope its more clear? thank you for your help
SugerCodeCude
SugerCodeCude el 5 de Jul. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 5 de Jul. de 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.
  1 comentario
SugerCodeCude
SugerCodeCude el 5 de Jul. de 2019
Thank you, this too helps histcount2. I will contiune to look into this.
Thank you again all!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by