Is it possible to use variable-sized lookup table in a compiled Simulink Model

6 views (last 30 days)
Hello,
some colleagues of mine need to compile their Simulink models. They use lookup table that they feed with excel tables. The dimension of those tables can change. Is there a way to compile the model or a lookup table block which can use variable-sized parameters ?
Thank you

Accepted Answer

Matt Cohen
Matt Cohen on 19 May 2016
Hi Denis,
I understand that you are interested in whether or not there is a way to use a lookup table block which can use variable-sized parameters.
From the documentation for the various lookup table blocks provided in Simulink, it appears that none of the them support variable-size signals. However, there appears to be a workaround for accomplishing this task. To accomplish this, you can make use of the "interp1" MATLAB function and the MATLAB function block in Simulink.
I have provided a ZIP-file containing a model called "variable_size_lookup_table.slx" that contains a MATLAB function block that acts as a variable-size lookup table by using the "interp1" function. The following example code declares variables and generates some test data, and then simulates the model provided:
% Declare variables
xdata = linspace(-2 * pi, 2 * pi);
ydata = sin(xdata);
xdata2 = linspace(-4 * pi, 4 * pi, 50);
ydata2 = cos(xdata2);
% Simulate
mdl = 'var_size_lookup_table';
sim(mdl);
figure(1); clf();
subplot(2, 1, 1);
% Note the lookup table change at t = 1, with different sizes
plot(tout, yout);
I have also provided some additional example code for performing the code generation and verifying the output:
% Generate Code, execute to verify
rtwbuild(mdl);
system([mdl, '.exe']);
data = load([mdl, '.mat']);
subplot(2, 1, 2);
plot(data.rt_tout, data.rt_yout);
One thing I should note is that you will not be able to output continuous samples by this method. You would need to do a rate transition from continuous to discrete samples, and then go back to continuous in the end. Another thing to note is that this example uses the "ert.tlc" system target file, which requires Embedded Coder. To test this without Embedded Coder, use the "grt.tlc" file instead. Please also note that I have only tested this in MATLAB R2014b and R2016a.
I hope this information proves to be helpful.
Matt
  1 Comment
Denis LE BRET
Denis LE BRET on 20 May 2016
Thank you Matt for your answer. It looks good. sadly, I didn't manage to run your model. Maybe because I use R2013a, or maybe something is missing (nothing within the Matlab function bloc). Could you please, post the inside code of the Matlab function bloc ?

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Coder 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!