How do we write a code for a periodic intermittent scalar function?

12 ビュー (過去 30 日間)
Eric Mwanandiye
Eric Mwanandiye 2018 年 11 月 9 日
回答済み: Eric Mwanandiye 2018 年 11 月 29 日
I would like to write a code of an periodic intermittent bounded control. I've tried to write it as a piecewise function but its not giving me type of output I want. Can someone help please? This what I have written
K = 0:0.01:1;
Pk =[];
m = 4; h = 0.1; T = 0.05;
for k = 1:length(K)
if (K(k) >= m*T & K(k) < m*T + h)
pk = 4;
elseif (K(k) >= m*T + h & K(k) < (m+1)*T)
pk = 0;
end
Pk = [Pk pk];
end
  4 件のコメント
Eric Mwanandiye
Eric Mwanandiye 2018 年 11 月 9 日
However, I want something like this
Walter Roberson
Walter Roberson 2018 年 11 月 9 日
And what do you expect instead?

サインインしてコメントする。

採用された回答

Eric Mwanandiye
Eric Mwanandiye 2018 年 11 月 29 日
Here is what I wanted. I've solved it.
clear all; close all; clc;
N = 0.2;
h = 0.5;
n= 0:25;
t = 0:0.001:5;
for i = 1:length(n)
for j = 1:length(t)
if (t(j) >= n(i)*N)&(t(j) < (n(i) + h)*N)
k(j) = 2;
elseif (t(j) >= (n(i) + h)*N)&(t(j) < (n(i) + 1)*N)
k(j) = 0;
end
end
end
plot(t,k,'linewidth',2)
axis([0 5 0 2.5]);

その他の回答 (0 件)

カテゴリ

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