How do I define piecewise constant function in for loop?

8 ビュー (過去 30 日間)
Saurabh Madankar
Saurabh Madankar 2023 年 10 月 28 日
編集済み: Dyuman Joshi 2023 年 10 月 28 日
For example, say I have data points given by
,
and corresponding output points. Now I want to define a piecewise constant function y such that on its , on , on , on and so on.

採用された回答

Torsten
Torsten 2023 年 10 月 28 日
編集済み: Torsten 2023 年 10 月 28 日
Give the correct values to the arrays "left_limit_of_ith_interval" and "right_limit_of_ith_interval" in the following code:
left_limit_of_ith_interval = ...;
right_limit_of_ith_interval = ...;
fun = @(T)0;
for i = 1:M-1
fun = @(T) fun(T) + x(t(i)).*(T>=left_limit_of_ith_interval(i)).*(T<right_limit_of_ith_interval(i));
end
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 28 日
編集済み: Dyuman Joshi 2023 年 10 月 28 日
I was about to implement a similar idea, with piecewise, but saw this answer.
How about this?
M=5;
t = ((1:M)-1/2)/M;
t = [0 t+t(1)]
fun = @(T) 0;
for i = 2:M
fun = @(T) fun(T) + x(t(i)).*(T>=t(i-1)).*(T<t(i));
end

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

その他の回答 (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