Replicating a plot over multiple periods in the same figure

6 ビュー (過去 30 日間)
Ammar
Ammar 2011 年 11 月 4 日
I have a piecewise function defined by the following:
v = @(t,a,b) (t>=a) & (t<b);
f=@(t) 0.*v(t,-1,0) + 2*t.*v(t,0,0.5) + 0.*v(t,0.5,0.5) +...
(2*t-2).*v(t,0.5,1) + 0.*v(t,1,2)
t=[0:0.01:1];
I can plot this function over the interval (0,1), but I need to plot it over several intervals, while maintaining the shape and values of the function.
Note: The lower and upper limits of t in the function can be increased and decreased.
Thanks all.
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 4 日
You might as well simplify your function to
f = @(t) 2*t.*v(t,0,0.5) + (2*t-2).*v(t,0.5,1)
as the 0.* parts are never going to add anything to the sum.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 4 日
If a and b are varied, then you need to put a and b as input arguments for f too.
Even with that, I think it's still hard to make it work for any time interval as a and b need to vary according to the time.
You might take a complete different route to make the function. Is that you need to create a saw-tooth wave signal? What are the required calibration parameters, the frequency, the magnitude? Once you put down those requirements, I think there is a better way to do this.
t=0:0.01:1;
y=@(t) mod(2*t-1,2)-1;
figure(2);plot(t,y(t));
t=-1:0.01:2;
figure(3);plot(t,y(t));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStair Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by