Graphing a periodic rectangular function

6 ビュー (過去 30 日間)
Kevin Klaus
Kevin Klaus 2016 年 9 月 21 日
回答済み: KSSV 2016 年 9 月 21 日
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.

回答 (1 件)

KSSV
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.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by