MATLAB: Use Simulink time variable in a Matlab Function

matlab functionsimulinktime

Hello everybody,
I want to implement a Matlab function into my Simulink Model, where I upconvert a signal to 24 GHz. I therefore want to implement the function y = real(u*exp(i*2*pi*24e9*t) as a Matlab function, where u is a complex time signal which is created in Simulink and t stands for the time in Simulink. I now somehow need to get the variable t of my Simulink project into my Matlab function in order to calculate the given function, but I dont know how to implement the variable t.
Thanks in advance for helping.

Best Answer

You can directly create MATLAB function inside Simulink using MATLAB function block: https://www.mathworks.com/help/simulink/ug/creating-an-example-model-that-uses-a-matlab-function-block.html. To feed the simulation time, use the clock block: https://www.mathworks.com/help/simulink/slref/clock.html.