Use Simulink time variable in a Matlab Function

137 ビュー (過去 30 日間)
Thomas Schütz
Thomas Schütz 2020 年 9 月 23 日
編集済み: Matthew Mishrikey 2021 年 12 月 10 日
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.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 23 日
編集済み: Ameer Hamza 2020 年 9 月 23 日
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.
  3 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 9 月 23 日
I am glad to be of help!
Matthew Mishrikey
Matthew Mishrikey 2021 年 12 月 10 日
編集済み: Matthew Mishrikey 2021 年 12 月 10 日
I tried to do something like your suggestion using a function block, but Matlab says it contains a block that updates persistent or state variables while computing outputs and is not supported in an algebraic loop.
function switch_control = current_monitor(current, clock)
persistent starttime;
persistent tripped;
if isempty(starttime)
starttime = 0;
end
if isempty(tripped)
tripped = false;
end
if (current > 10)
starttime = clock;
if ((clock - starttime) > 0.2)
tripped = true;
end
end
if(tripped)
switch_control = 0;
else
switch_control = 1;
end
end

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by