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

조회 수: 4 (최근 30일)
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

채택된 답변

Matt Cohen
Matt Cohen 2016년 5월 19일
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
Denis LE BRET
Denis LE BRET 2016년 5월 20일
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 ?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by