Use of Matlab Function in State Space Modeling gives Dimension Errors - S-Function needed?
1 view (last 30 days)
Show older comments
Dear Community,
I am modeling a heat transfer problem using a state space model. For that I used the Matlab Function block, which looks approximately like this:
function [x1p, x2p, x3p] = fcn(x1, x2, x3, u1, u2, u3, u4, u5, u6, u7, u8, u11, u12)
parameter1 = ...;
parameter2 = ...;
parameter3 = ...;
etc.
[...]
x1p = ...; %ode1
x2p = ...; %ode2
x3p = ...; %ode3
The list of parameters is quite long. What I want to do is exclude them from the matlab function and initialize them once via the accompanying script. Apparently because of the loop that is necessary (see the attached picture), I get dimension errors, when I do delete the constant parameters in the matlab function and initialize them from my script.
What do I need? Is it an S-function, or a Level-2 Matlab S function? I have zero experience with those, but I found via the search that the Matlab function treats its parameters as "persistent variables", in other words local to the function, if I understand correctly.
Can you give me any advice on how to treat this problem?
Thanks in advance
Felix
Edit: Error message looks like this:
Simulation
1
Clear
05:16 PM Elapsed: 1 sec
Compilation of model 'test' failed while trying to resolve underspecified signal dimensions.
Suggested Actions
Enable 'warning' or 'error' diagnostics for the list of underspecified signal dimensions.Open
Caused by:
- Error in default port dimensions function of S-function 'test_sfunc/Subsystem/Matlab Function'. This function does not fully set the dimensions of output port 2
6 Comments
darova
on 8 Apr 2020
Edited: darova
on 8 Apr 2020
There is one more way (but is not recommended): using global variables. See of one of topics: LINK
somewhere in main script
global a b c
a = 2;
b = 3;
c = 4;
then to use them in a function
function dx = f(t,x)
global a % don't forget declaring
dx(1) = a*x(1);
end
Answers (0)
See Also
Categories
Find more on Simulink Environment Customization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!