Clear Filters
Clear Filters

Use griddedInterpolant in MATLAB Function / Alternative to Simulink Functions in For Each Subsystem?

8 views (last 30 days)
Long Version (short version of the question below):
I have coded a custom Kalman-Filter-like MATLAB Function which I intend to use in a Simulink model. In order to make the block more universally usable, I used Simulink Function blocks, which contain the respective state space models for the filter. These models are a combination of MATLAB Functions and 2-D Lookup Table blocks. This works quite well for the case of a single model.
However, to make the filter even more universal and modular I intended to use a For Each Subsystem block. I thought, in that way I could use the filter efficiently for multiple similar systems, which use the same model. But the For Each Subsystem does not allow for the use of Simulink Functions.
So I tried to include the model in the filter code (which already compromises universability). However, now I'm facing the problem of using lookup tables within the MATLAB Function. Specifically, I need to use a (preferably efficient griddedInterpolant) 2D lookup table. So here comes the core of my question:
Short Version:
  • How can I use griddedInterpolant in a MATLAB Function in Simulink?
  • Is there a better alternative way to make my filter block universally usable (preferably with an external model)? i.e. is there an alternative to Simulink Functions for a For Each Subsystem?
Would be great if anynone could help me with this.
Thanks in advance!

Answers (1)

Honglei Chen
Honglei Chen on 10 Oct 2018
For the first question, the following link shows all supported functions for code generation and griddedInterpolant is not in it, so I don't think you can use it in MATLAB Function Block
However, since it's gridded, you may want to take a look at interp1, interp2, and interpn depending on your use case and these do support codegen.
For the second question, I'm not an expert on For Each Subsystem. But have you considered putting your block in a library so other model can use it?
HTH
  1 Comment
M. Kohler
M. Kohler on 10 Oct 2018
In the meantime I found out that I can use
coder.extrinsic('griddedInterpolant');
in the MATLAB Function. That way, I can use griddedInterpolant. It might not be the best way, but it works for now.
For the second part of your answer: I think I might not have been clear about what I'm trying to achieve. I probably should also clarify what I mean with "model" in my question. As I wrote above, I have implemented a Kalman-Filter-like function. The model I was refering to in the question is the state space model used by this filter.
In the simple case I have measurement signals from one physical system which are processed by the Kalman-Filter. I would now like to make the filter useable for multiple similar physical systems, i.e. use one filter block for multiple muxed measurement signals from different (but similar) physical systems. I don't want to simply copy the filter multiple times (which you kind of indicated by creating a block library), since my final goal is to have a filter block which can process multiple measurement signals. The dimensons should be easily user definable by a few mask parameters.
I hope that makes things clearer. Nevertheless, thank you for your answer.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!