How to create a periodic function?
이전 댓글 표시
The function at [0,2] is y=x for [0,1] and y=2-x for [1,2], I want the above function repeated at [2,10], so I need a periodic funtion in the whole [0,10], who can help me code it ,thank you.
채택된 답변
추가 답변 (2개)
David Hill
2020년 11월 25일
y=zeros(size(x));
for k=1:5
y(x>=(k-1)*2&x<(k-1)*2+1)=x(x>=(k-1)*2&x<(k-1)*2+1);
y(x>=2*(k-1)+1&x<2*k)=2-x(x>=2*(k-1)+1&x<2*k);
end
댓글 수: 4
huazai2020
2020년 11월 25일
David Hill
2020년 11월 25일
Are your functions changing? Recommend showing us the input and output you want.
Image Analyst
2020년 11월 25일
Then just use the code that you used to create the figure. It's what you want isn't it?
huazai2020
2020년 11월 25일
Setsuna Yuuki.
2020년 11월 25일
You can use this function: https://es.mathworks.com/matlabcentral/fileexchange/83058-continuous-piecewise-function-linear-funcion-por-partes
x = [0:3:36];
y = [0 1 0 1 0 1 0 1 0 1 0 1 0];
sig = pwfun(x,y);
and create the waveform only with the intersection points.

카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



