# Defining a time varying function

5 Ansichten (letzte 30 Tage)
Deepa Maheshvare am 25 Feb. 2020
Kommentiert: Adam am 26 Feb. 2020
I'd like to create a function that will output a value of a (e.g. a = 10) for time < t0 and value equal to b at time > t0.
Any suggestions on how to create such a function in MATLAB will be helpful
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Bearbeitet: Adam am 25 Feb. 2020
if t < t0
result = a;
else
result = b;
end
gives what you want for this simple case, provided t0, a, b and t are all passed into the function or defined at the top of the function. If it where more complicated I might suggest other methods but a simple binary threshold output works fine with an if statement.
##### 2 KommentareKeine anzeigenKeine ausblenden
Deepa Maheshvare am 26 Feb. 2020
Many thanks for the answer. Binary threshold output works fine but it creates a discontinuity at t = t0. Could you please suggest continuous functions ? For instance when a > b, I'd like to create a function that will gradually decrease from a to b.
You'd need to rephrase the question to more precisely ask what you want in that case. To fulfill what you asked in the question then including a reasult of mean( [a, b] ) for t == t0 would be the only approach that is slightly less discontinuous.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by