How do I define piecewise constant function in for loop?
조회 수: 15 (최근 30일)
이전 댓글 표시
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.
. Now I want to define a piecewise constant function y such that on
its
,
,
and so on.댓글 수: 0
채택된 답변
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
2023년 10월 28일
편집: Dyuman Joshi
2023년 10월 28일
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 Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!