How to interpolate/extract row from essentially 1-D lookup table
조회 수: 9 (최근 30일)
이전 댓글 표시
I have an n x 3 matrix of backEMF values (one per phase) that all map to the same n x 1 vector of position data. For a given position, I would like to interpolate the backEMF value of each phase in the most efficient way possible.
I can use 3 1-D lookup tables (one per phase), but that seems wasteful with respect to re-calculating the index and fraction and then the interpolation definitely isn't parallelized. I could also use a single 2-D lookup table with the 2nd dimension of breakpoints set to [1,2,3] and the second input also set to [1,2,3] but that seems innefficent as it is now doing a 2D lookup for each value. I also looked at the Prelookup->Interpolation Using Prelookup both in parallel (one per phase) and a 2-D "vectorized" version in which the 'Number of subtable selection dimensions' is set to 1 with an input of [0 1 2] (I couldn't get it to give all three results otherwise, only the first two with an input of [0 1 2] and [0 0 0]) and it performs somewhere between the 3*1D table look ups and the 2D table lookup block.
Matlab does a great job vectorizing things and I would love to take advantage of that for this application.
I am essentially looking for the equivalent of the Selector block having "Select all" as an Index Option. If that's not possible, then I'll probably go with the 2D table lookup as it's consistently slightly faster than the 2D prelookup method and much faster than the other two.
Cheers!
댓글 수: 0
채택된 답변
Matt J
2024년 12월 13일
편집: Matt J
2024년 12월 13일
The interpolated table data given to a 1D Lookup Table can have multiple columns. So just set it to backEMF as is.
댓글 수: 3
Matt J
2024년 12월 13일
I don't know what "complains" means. You need to copy /paste the error messages.
Another approach might be to use a Matlab Function block, coded as below:
function y = fcn(x)
% Example column-wise interpolation using interp1
% Define the breakpoints (input values) and table data (MxN matrix)
breakpoints = [1, 2, 3, 4, 5]; % Input breakpoints (rows)
tableData = [ 1 2 3;
4 5 6;
7 8 9;
10 11 12;
13 14 15]; % MxN matrix
% Perform column-wise interpolation
y = interp1(breakpoints, tableData, x, 'linear', 'extrap');
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Nonlinearity에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!