how to create a look up table to use in simulink from a 2D array of doubles
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert Scott
am 13 Dez. 2023
Kommentiert: Robert Scott
am 15 Dez. 2023
I have a simple 2 day array that is 40x2
I want to make it a look up table for simulink.
it needs to be interpolated not a direct.
So i want simulink to scan the first column and find the value closed to the one im inputting and them pump out the value in the second column that corresponds to the input found in column one.
This should be really simple. Can someone lend a hand?
thanks
1 Kommentar
madhan ravi
am 14 Dez. 2023
Bearbeitet: madhan ravi
am 14 Dez. 2023
Sure, give a simple example and expected output.
Akzeptierte Antwort
Paul
am 15 Dez. 2023
Bearbeitet: Paul
am 15 Dez. 2023
Assuming your 40x2 array is stored in a workspace varaiable named data.
Set the Table Data parameter to data(:,2)
Set the Breakpoints parameter to data(:,1)
Set the Interpolation Method to Nearest.
Depending on the structure of data(:,1) make sure to check into the following block parameters: Index search method, and Begin index search using previous index result
I think this addresses the problem as stated in the question. But the question also mentioned interpolation, and there is no interpolation happening here.
8 Kommentare
madhan ravi
am 15 Dez. 2023
Paul you could show the picture of Table and breakpoints field so that it is clear for OP how to define them in Simulink.
Weitere Antworten (2)
Andy Bartlett
am 14 Dez. 2023
Bearbeitet: Andy Bartlett
am 14 Dez. 2023
To create a Simulink 1D Lookup Table block using the data from your 2D matrix variable,
modify this script to meet your needs and run it.
% fake creation of data
%
npts = 5;
x = linspace(0.1,1,npts).';
y = exp(1.234*x);
data2D = [x, y];
% Create model containing 1D LUT block
%
rand_trailing_string = dec2hex( randi([0,2^32-1],1,1), 8 );
mdl = sprintf('myRandModelName_%s',rand_trailing_string);
sourceLUT1 = sprintf('simulink/Lookup\nTables/1-D Lookup\nTable');
destinationLUT1 = [mdl,'/LUT'];
new_system(mdl);
open_system(mdl);
add_block( sourceLUT1, destinationLUT1)
dataConnectionApproach = 'inline';
switch dataConnectionApproach
case 'inline'
% explicitly inline the data values
% Hint: mat2str is super helpful here
%
stringForBreakpoints = mat2str(data2D(:,1),17,'class');
stringForTableData = mat2str(data2D(:,2),17,'class');
otherwise
% Reference data in workspace by variable name
% Note: data must always be defined before model is used
% in the future
%
stringForBreakpoints = 'data2D(:,1)';
stringForTableData ='data2D(:,2)';
end
set_param(destinationLUT1, 'BreakpointsForDimension1', stringForBreakpoints);
set_param(destinationLUT1, 'Table', stringForTableData );
% Make additional changes to LUT as desired
% Either
% Manually
% or
% use set_param
%
% Hint to see names of parameters to use with set_param do
%
% get_param(gcb,'DialogParameters')
%
open_system(destinationLUT1) % open for manual changes
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!