Profiling a variable within a function

I am trying to create a code that outputs the value of a funtion as it varies with time.. At the same time I want one of the variables in my function to have different values depending on the time interval being evaluated in that function. for example:
For simplification purposes, lets say my function is: f(t)= 5*t+G
I want the code to run from t=0 to t=900 [seconds]
For the first 300 second (t+0 to t<300) I want the value of G to be 10.
For the next 300 seconds (t=300 to t<600) I want g to equal 20
Finally, for the last 300 seconds (t=600 to t=900) I want G to equal 30.
Then I want the code to output a plot of f(t) vs. T
How can I do this?

 Respuesta aceptada

TADA
TADA el 4 de Feb. de 2019
G = @(t) (floor(t/300)+1)*10;
f = @(t) 5*t + G(t);
t = 1:899;
plot(t,f(t));

4 comentarios

David Cirino
David Cirino el 5 de Feb. de 2019
Can you explain the first line of code? Please
TADA
TADA el 5 de Feb. de 2019
The Function G Is a Partitioned Function Which Gives A Value Which Increments By 10 For Every Interval Of 300 (IE 0-299, 300-599, 600-899)
To Achieve This I Divided t By That Interval, Rounded Down, Added 1 (to Start From 10 And Not 0) And Multiplied By 10
David Cirino
David Cirino el 5 de Feb. de 2019
Thanks!
TADA
TADA el 5 de Feb. de 2019
Your welcome

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 4 de Feb. de 2019

Comentada:

el 5 de Feb. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by