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

2 views (last 30 days)
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

Accepted Answer

Steven Lord
Steven Lord on 26 Jun 2023
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 Comments
Steven Lord
Steven Lord on 26 Jun 2023
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 on 26 Jun 2023
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!