How to interpolate/extract row from essentially 1-D lookup table
42 views (last 30 days)
Show older comments
Sanders
on 13 Dec 2024 at 21:31
Commented: Sanders
on 13 Dec 2024 at 23:41
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 Comments
Accepted Answer
Matt J
on 13 Dec 2024 at 22:07
Edited: Matt J
on 13 Dec 2024 at 22:14
The interpolated table data given to a 1D Lookup Table can have multiple columns. So just set it to backEMF as is.
3 Comments
Matt J
on 13 Dec 2024 at 23:07
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!