Can I input an m file into a simulink model as a function block? If so, how?

1 回表示 (過去 30 日間)
Elena Vasiljevic
Elena Vasiljevic 2020 年 3 月 26 日
編集済み: Birdman 2020 年 3 月 26 日
I am currently working on a final year project exploring maglev energy harvesters. I have modelled the mechanical (similar to a quarter car model) and electrical (electrical circuit connected to coil) equations in simulink.
I have a matlab script which details a function for the electromagnetic coupling factor of the coil. I was wondering if there was a way of inputting this m file as a function block in the simulink model? There will be an input for the displacement of the magnet, as this is the only varying parameter and the other parameters (e.g. the geometrical dimensions of the coil) will remain constant.

回答 (1 件)

Birdman
Birdman 2020 年 3 月 26 日
Use MATLAB Function block.
  2 件のコメント
Elena Vasiljevic
Elena Vasiljevic 2020 年 3 月 26 日
Thank you!
How do I connect this to a specific script?
Birdman
Birdman 2020 年 3 月 26 日
編集済み: Birdman 2020 年 3 月 26 日
You do not connect. You rewrite your script as a function inside MATLAB Function block. For instance consider you have the following script:
x=5;
y=2*x;
You convert this into the function format as
function y=doubleX(x)
y=2*x;
end
Try to do it. Let me know the results.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by