How to implement modulo to the code

조회 수: 1 (최근 30일)
SugerCodeCude
SugerCodeCude 2019년 7월 4일
댓글: SugerCodeCude 2019년 7월 5일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by