switching functions for continuous time
3 ビュー (過去 30 日間)
古いコメントを表示
I am plotting a function for say:
t = 0:0.1:1 %seconds
I want to use one function for:
t < 0.2
One for:
t >= 0.2 & t <= 0.0.8
And then one for:
t >0.8
I can't get it to work using the conventions I have stated aboce
0 件のコメント
採用された回答
Walter Roberson
2011 年 5 月 25 日
y = zeros(size(t));
idx = t<0.2;
y(idx) = f1(t(idx));
idx = t>=0.2 & t<=0.08
y(idx) = f2(t(idx));
idx = t>0.8;
y(idx) = f3(t(idx));
0 件のコメント
その他の回答 (8 件)
A
2011 年 6 月 14 日
2 件のコメント
Walter Roberson
2011 年 6 月 14 日
"for" loop and an if/elseif structure if it is expensive to compute the values.
If computing the values is relatively cheap,
y = f1(x);
idx = find(y >= 80,1,'first');
y(idx:end) = f2(x(idx:end));
A
2011 年 6 月 21 日
5 件のコメント
Walter Roberson
2011 年 6 月 21 日
Good point about the index; sorry about that.
If your y are in increasing order, then
find(SpecificY < y,1,'last')
A
2011 年 6 月 23 日
3 件のコメント
Walter Roberson
2011 年 6 月 23 日
Time_Value = V_In * .632;
Time_Check = find(V_C_SS <= Time_Value,1,'last');
Time_Constant = t(Time_Check);
A
2011 年 6 月 23 日
4 件のコメント
Walter Roberson
2011 年 6 月 23 日
That's what the code you posted above does, unless f2 is sensitive to the position of the x as well as to the value of the x. If it _is_ sensitive to the position of the x, then the next thing we would need to know is whether the f2 values are calculated independently or if values from earlier input influence later output.
If there is dependence on the position then,
y = f1(x);
y2 = f2(x);
idx = find(y >= 80,1,'first');
y(idx:end) = y2(idx:end);
A
2011 年 6 月 23 日
1 件のコメント
Walter Roberson
2011 年 6 月 23 日
Time_Check = find(V_C_SS > Time_Value,1,'first') - 1;
Provided that your values do not start out above the time constant, dip, rise, with it being the point on the rise you want to get.
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!