I'm trying to write a funciton that has two outputs, 1 or 0. Based on the angle if its between 0 and 34 degrees its = 0. Then if it's between 34 and 68 = 1. That repeats itself 360 degrees. If anyone can help with the code for the fucntion it would be great! Currently I had:
function Thet = Theta (A)
returnValue = 1;
if mod(A, 68)~= 0
returnValue = 0;
end
Thet = returnValue;
end

 채택된 답변

madhan ravi
madhan ravi 2020년 7월 14일

0 개 추천

Theta = @(x) 0*(x>=0 & x<34) + 1*(x>=34 & x<=68)

댓글 수: 3

I don't see the pattern repeating all the way out to 360:
Theta = @(x) 0*(x>=0 & x<34) + 1*(x>=34 & x<=68)
angle = 0 : 360
out = Theta(angle)
madhan ravi
madhan ravi 2020년 7월 14일
편집: madhan ravi 2020년 7월 14일
Ok should have included that as well:
x = 394; % for example
Wanted = Theta(x)
function Thet = Theta(x)
x = mod(x, 360);
Thet = 0*(x>=0 & x<34) + 1*(x>=34 & x<=68);
end
Kyle Grimaldi
Kyle Grimaldi 2020년 7월 14일
Thank you for the response! The output is working for the first 0-68 but anything past that only outputs 0.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Powertrain Blockset에 대해 자세히 알아보기

질문:

2020년 7월 14일

댓글:

2020년 7월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by