[Simulink] Call the same Matlab function multiple times in a model

Hi,
I have a generic Matlab function describing the behaviour of an battery electrode and I would like to call it in my model with various parameters (one call for the positive electrode, and the other call for the negative electrode calculation).
In order to make my function generic, I use a structure that contains parameters of the positive and negative electrode so that calling it with argument "pos" or "neg" will make the calculations with whether positive or negative parameters. Unfortunately, Simulink sees that as a "non constant parameter" and refuses to operate.
Do you have an idea of a way to call my "unique function" twice in my model: one call for the negative electrode and an other call for the positive one?
Thanks!

댓글 수: 1

In other words, I have two sets of parameters (one for the positive electrode and another for the negative electrode), and I want to call a Matlab function with those two sets, without having to copy/duplicate the block.
For this matter, I was using a Data Dictionary containing each parameter as a structure with two fields : pos and neg.
Unfortunately, Simulink won't let you use the syntax "Param.(Electrode)" in a Matlab Function Block.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 7월 4일

0 개 추천

Use a Constant Block of signal type Boolean feeding into that parameter ?
Boolean because Simulink does not support signals that are type string.
https://www.mathworks.com/matlabcentral/newsreader/view_thread/45166

댓글 수: 6

Correct, I had to use an integer constant block and attribute "neg" to 1 and "pos" to 2. But when I want to access the parameter Rs for positive electrode (np=2) like :
Rs.(np)
the following error occurs :
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.
In this context, the value of the string must be known.
Even if np is filled from a constant block!
parmnames = {'neg', 'pos'};
Rs.(parmnames{np}+1)
possibly?
The use of structure and dynamic field call is not supported in Simulink. The code issued the following error :
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.
That's the reason why I'm looking for another way to use the same function with my two sets of parameters.
Well then
if np == 0
params = Rs.neg;
else
params = Rs.pos;
end
Right, this is what I've finally done. But I'm still not very confident with the way I manage my parameters (Data Dictionary and Structures). Is there some Best Practices for using parameters of that kind in a Simulink Model?
Thank you again for your time.
Sorry I do not know about that.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Simulink Functions에 대해 자세히 알아보기

질문:

2016년 7월 4일

댓글:

2016년 7월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by