How to implement modulo to the code

1 次查看(过去 30 天)
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 个评论
SugerCodeCude
SugerCodeCude 2019-7-5
编辑:SugerCodeCude 2019-7-5
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 2019-7-5
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
Guillaume 2019-7-5
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 个评论
SugerCodeCude
SugerCodeCude 2019-7-5
Thank you, this too helps histcount2. I will contiune to look into this.
Thank you again all!!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by