Graphing a periodic rectangular function
조회 수: 5 (최근 30일)
이전 댓글 표시

How would I represent this as a periodic rectangular function, assuming that the 'n' variable represents integers. I'm a little confused on how to define a variable as an integer as well.
댓글 수: 0
답변 (1개)
KSSV
2016년 9월 21일
clc; clear all ;
N = 10 ;
x = 1:200 ;
f = zeros(length(x),N) ;
for n = 1:N
for i = 1:length(x)
if x(i)>=2*n && x(i)<= 2*n+1
f(i,n) = 1 ;
else
f(i,n) = 0 ;
end
end
end
plot(x,f,'r')
It can done without loops also.
댓글 수: 0
참고 항목
카테고리
Help Center 및 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!