Graphing a periodic rectangular function

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.

Antworten (1)

KSSV
KSSV am 21 Sep. 2016

0 Stimmen

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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 21 Sep. 2016

Beantwortet:

am 21 Sep. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by