필터 지우기
필터 지우기

numerate two numerators in conjunction with each other

조회 수: 2 (최근 30일)
fatema saba
fatema saba 2015년 11월 8일
답변: Walter Roberson 2015년 11월 8일
Hello
I have two numerator, A and B.
in steps 1 to 6 when A numerates 1 to 6, B is 1.
in steps 7 to 12 when A numerates 1 to 6, B is 2.
in steps 13 to 18, A numerates 1 to 6, B is 3.
in steps 19 to 24, A numerates 1 to 6, B is 4.
In steps 25 to 30, A numerates 1 to 6, B is 5
and in steps 31 to 36, A numerates 1 to 6, B is 6.
from step 37 condition is conversed. it means that from step 37 to 42, A is 1 and B changes between 1 to 6. then from step 43 to 48, A is 2 and B changes between 1 to 6. this process will continue until step 73. from this step, condition is similar to steps 1 to 36.
Is it possible to help me please.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 8일
B = mod( ceil(step/6) - 1, 6) + 1;
The ceil(step/6) is pretty straight forward. 1 to 6 become 1, 2 to 12 become 2, ... 31 to 36 become 6, 37 to 42 become 7, 43 to 48 become 8, and so on.
mod(Value - 1, Range) + 1
is a little calculation trick. If you were to values 1 to 8 and take them mod 6, you would get 1 2 3 4 5 0 1 2 -- with a 0 in the places you want a 6. You could post-process with logical indexing or a loop to change the 0 to 6, but that is inconvenient. But look what happens if you subtract 1 before taking the mod 6: you get 0 1 2 3 4 5 0 1 . Add 1 to that and you get 1 2 3 4 5 6 1 2, exactly what you need. There are Good Reasons why this works, but it is easier to just remember the trick "subtract 1 first, add 1 after" than to work out the mathematics of it each time ;-)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by