How to implement a look up table in simulink which can accept variable SIZE data as inputs

조회 수: 50 (최근 30일)
Hi.
How to implement a look up table in simulink which can accept variable SIZE data as inputs. So for example I am using a 1-D lookup table which ideally accepts a 15x1 vectors (each) as my table data and breakpoints. Both the vectors are monotonically increasing. This is the ideal condition. However, I also must do a data processing of the vectors before they are fed to the LUT. I want to remove zeros or negative numbers from one of the 2 vectors and I must shorten the other vector accordingly. Let's say for example I have one of the vectors with two 0s or two negative numbers, here I process the data so that I filter out these two vector elements and effective vector output size now is only 13 instead of 15 (for both the Table data and BP, i.e. I always make the size of these two vectors equal before using the LUT). This size can also now become 12 or 11 or 10 depending on how many invalid elements I have in my vector inputs. The LUT now does not accept variable size vectors a inputs as it always expects fixed sized Table data and BP.
Is there a solution for this? Is there a specific LUT type that I can use for this purpose?
Regards
Ganesh Iyer
  댓글 수: 2
Paul
Paul 2023년 1월 11일
편집: Paul 2023년 1월 12일
Hi Ganesh,
Suppose you start with 15 breakpoints. After the processing you end up with 13 breakpoints and 13 associated data points. Now, what should happen if the indepedent variable into the LUT is greater/lesser than the maximum/minimum breakpoint? Do you want to use the endpoint of the data points? Or extrapolate the data points?
Ganesh Iyer
Ganesh Iyer 2023년 1월 12일
Hi Paul, Thanks for your response. I have a matlab function which receives vector inputs from another subsystem (which are considered as table data and breakpoints by my LUT). Now these vectors are always of the size 15x1. However The matlab function that I mentioned before, this fucntion can trim the 15x1 vector and filter out some invalid values and can thus change (or rather shorten) the size to let's say either 13x1 or 10x1 or 6x1 vectors. These trimmed/reshaped vectors are then used by the LUT. So in any case, the LUT will always receive BP and Table data which have equal sizes but not necessarily 15x1 which is the original intended maximum size. In an ideal situation where both the input vectors have all 15 valid elements/numbers, the LUT is expected to give a precise lookup value depending on the requested input. But considering decisions by preceding subsystem logics, they may fill some of the elements in the 15x1 vectors with some zeros or negative numbers. The matlab function mentioned earlier kicks out these unwanted elements and provides a clean (but shorter) vector set to the LUT.
When this change in the size happens, the LUT does not accept. LUT apparently always requires that the BP and table data are always of consistent size (it doesnt care if it is 15x1 or 13x1 or 7x1, so long as it remains fixed always). And thagt is my problem.

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

채택된 답변

Paul
Paul 2023년 1월 12일
편집: Paul 2023년 1월 12일
Accroding to the doc, the LUT Dynamic block doesn't accept variable size signals.
I tried the following approach, which sounds like the path you might already be going down.
I tried this methos, which assumes that we want to clamp the independent variable to the endpoints of the table breakpoints when it is outside the breakpoints. The other blocks are Saturation Dynamic and Lookup Table Dynamic.
The Matlab Function block is:
function [maxxdata,minxdata,xdataout,ydataout] = fcn(xdatain,ydatain)
% remove points where xdatain = 0
% the leading elements of xdataout will be valid breakpoints. the trailing
% elements of xdataout are padding and shouldn't ever actually be used in LUT.
% the leading elements of ydataout will be the elements of ydatain that
% correspond to the good elements of xdatain
xdataout = 0*xdatain;
ydataout = 0*ydatain;
baddata = xdatain == 0;
numbad = sum(baddata);
numgood = numel(xdatain) - numbad;
maxxdata = max(xdatain(~baddata));
minxdata = min(xdatain(~baddata));
xdataout(1:numgood) = xdatain(~baddata);
xdataout(numgood+1:end) = (maxxdata + 1)*(1:numbad);
ydataout(1:numgood) = ydatain(~baddata);
end
  댓글 수: 1
Ganesh Iyer
Ganesh Iyer 2023년 1월 13일
Thanks a ton Paul,
Your solution and mat function gave me some ideas on improving my logics. Though I was not able to completely use your idea as it is, I derived some intelligence from it. I wrote a function to first filter the incoming data by finding elemnts which are 0s (find block and mat function intersect for finding common invalid values from x_in and y_in) and then knocking them out. Then I sorted them and checked if they are really sorted monotonically. At this stage my vector is already reduced to 12 (3 invalid elements as per my trial). Then I moved the 12th element to the 15th position and interpolated some points between 11th and 15th element. This now makes the vector of size 15 and I can define the outputs in my model explorer as fixed size of 15. Now this data is fed to a 1-D LUT and now everything works fine.
So to conclude, in order to make the LUT block work, some pre processing has to be done for this version(R2022a) of matlab simulink.
By the way, I also check with Mathworks team and they said they are considering upgrading the LUT to accept variable size data in the future :)
But for now, thanks for your time and thanks for trying.

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2023년 1월 12일
You must be using the "Lookup Table Dynanic" block for this. Accordig to its doc, it does not support 'variable-size signals". So the answer is no.
There might be a solution using a MATLAB Function block, which supports variable-size signals. Both the break points data and table data are inputs to the MATLAB Functon block. Inside, use interp1() to do the lookup.
web(fullfile(docroot, 'simulink/slref/lookuptabledynamic.html'))
web(fullfile(docroot, 'simulink/ug/variable-size-signal-basics.html'))
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2023년 1월 12일
There is no direct way for "using variable size data with 1-D LUT simulink block", be it the "1-D Lookup Table" block, or the "Lookup Table Dynamic" block.
Check this out. web(fullfile(docroot, 'simulink/ug/guidelines-for-choosing-a-lookup-table.html'))
There is no mention of "variable-size data". A few options support "Dynamic breakpoint data" or "Dynamic table data".
You need to find a block that supports "variable-size data" to provide the "Dynamic breakpoint/table data". MATLAB Function block is one of them.
Ganesh Iyer
Ganesh Iyer 2023년 1월 13일
Hi Fangjun, Thanks a lot for your time. I will check if there are any workarounds for this.

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

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by