Use of Matlab Function in State Space Modeling gives Dimension Errors - S-Function needed?

8 ビュー (過去 30 日間)
Felix Schönig
Felix Schönig 2019 年 11 月 19 日
編集済み: darova 2020 年 4 月 8 日
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 件のコメント
Felix Schönig
Felix Schönig 2020 年 4 月 8 日
Thank you! Even though that is not the solution I had wished for (without having to initialize another list of parameters with par1 = ... par2 = ...), it sounds like a good workaround to centralize my parameter list via the .mat file. I will try it tomorrow. :) Thanks so much and have a good evening!
darova
darova 2020 年 4 月 8 日
編集済み: darova 2020 年 4 月 8 日
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

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by