필터 지우기
필터 지우기

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

조회 수: 5 (최근 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