How to call a symbolic function from a Simulink's MATLAB Function block?

1 次查看(过去 30 天)
So I have this complicated interpolating symbolic function that is in my workspace that I am trying to call from my Simulink module to use, is that possible? If so, how can I do that?
Because currently what I am doing is that I saved that symbolic function in a .mat file and I am loading it in my Simulink module each time I would like to use it in my MATLAB Function block. But is there a way to load that symbolic function once to my matlab basic workspace, and then from it call my symbolic function in my MATLAB Function Block ?
An example of a symbolic function: F = @(x) x^2

采纳的回答

Steven Lord
Steven Lord 2023-6-26
An example of a symbolic function: F = @(x) x^2
No, as written that's an anonymous function not a symbolic function. Depending on how pedantic you want to be a symbolic function could be something like either g or f(x) in the code below:
syms x y f(x)
g = x.^2+y.^3
g = 
f(x) = sin(x+1)
f(x) = 
whos x y g f
Name Size Bytes Class Attributes f 1x1 8 symfun g 1x1 8 sym x 1x1 8 sym y 1x1 8 sym
If what you have is more like g or f the matlabFunctionBlock function may be of use to you. Use that function to generate the block to use in your model.
If that's not what you mean by "symbolic function" please show us exactly how you create your symbolic function.
  3 个评论
Steven Lord
Steven Lord 2023-6-26
If you have a 10 MB anonymous function, perhaps you should write it as a regular MATLAB function file instead.
If most of that is data used by the file, I'm not 100% certain but you may want to look at storing that data somewhere other than a MAT-file. This documentation page and this other documentation page may be of use in determining the right place to store that data for your MATLAB Function block to use.
Ali Almakhmari
Ali Almakhmari 2023-6-26
I will try to look into the documentation pages you sent. But I dont think your first suggestion of writing it as a regular MATLAB function file is suitable because I do have that function file that generates that anonymous function for me, but it takes a long time to run. If you have any other suggestions let me know.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by