Interpolation of 2D-Table Data

26 次查看(过去 30 天)
Mapete
Mapete 2022-6-7
回答: Tushar 2023-9-5
Hello,
i have the following table with three values:
The calculated value for n is n = 1867 U/min and for the Motormoment M = 12,65 Nm.
What i need to calculate/interpolate is the corresponding value "alpha". How is that possible in a matlab function that i can use in my Simulink-Model?
Thanks!
  3 个评论
Mapete
Mapete 2022-6-7
@KSSV thanks for your quick answer. Have a look at what i have tried so far with the interp functions:
It still doesn´t work.
Mapete
Mapete 2022-6-7
I need to know the value B for the known values A = 12.65 and C = 1867.

请先登录,再进行评论。

回答(1 个)

Tushar
Tushar 2023-9-5
Hi Mapete,
I understand that you are trying to interpolate the corresponding value of 'alpha' when A=12.65 & C=1867. Note that the resulting value may not be exactly 12.65 or 1867 due to the nature of interpolation and the available data points. Here is the code sample. I have added comments so that it would be easier to modify the values as and when needed:
function requiredAlpha = requiredAlpha(A,B,C,requiredA,requiredC,precision,interpolationType)
% Define the X and Y coordinates for the grid
[X, Y] = meshgrid(1:size(A), 1:size(A));
% Define the required resolution of the interpolated data
numPointsX = precision; numPointsY = precision;
minX = 1; maxX = size(A,2);
minY = 1; maxY = size(A,1);
% Create the new grid for interpolation
[Xq, Yq] = meshgrid(linspace(minX, maxX, numPointsX), linspace(minY, maxY, numPointsY));
% Interpolate the data
interpolatedDataA = interp2(X, Y, A, Xq, Yq, interpolationType);
% Defining some vectors to be used while interpolating both B and C
X = 1:length(B);
Xq = linspace(minX, maxX, numPointsX);
% Interpolating B
interpolatedDataB = interp1(X, B, Xq, interpolationType);
% Interpolating C
interpolatedDataC = interp1(X, C, Xq, interpolationType);
% Finding the required Alpha value
[~, required_C_index] = min(abs(interpolatedDataC(:) - requiredC));
[~, index] = min(abs(interpolatedDataA(:,required_C_index) - requiredA));
[required_B_index, ~] = ind2sub(size(interpolatedDataA), index);
requiredAlpha = interpolatedDataB(required_B_index);
end
% given data
A = [[110,110,110,110,110,110,110,110]',[110, 106, 105, 100,95,90,55,27]',[125,115, 110, 105, 100,80,50,0]',[140,140,130,125,100,65,20, -32]',[170,160,150,110,75,35,-25,-51]',[185,165,155,95,50,20,-40, -60]',[200,175,160,70,25,-10,-50, -63]',[190,155,140,40,-20,-40,-60,-65]'];
B = [0,5,10,15,20,30,40,90];
C = [300,800,1000,2000,3000,4000,5000,6500];
% required data
requiredA = 12.65;
requiredC = 1867;
precision = 10000; % this will result in the number of points in the grid made. The more the precision value, the more number of points would be interpolated and the closer you will get to the required Alpha value.
% I found that precision value of 10e4 or 10e5 gives similar results
interpolationType = 'spline'; % look at the documentation provided and choose the preferred type
% calling the function to get the answer
Alpha=requiredAlpha(A,B,C,requiredA,requiredC,precision,interpolationType);
I hope the comments are adequate enough. Attaching some documentation to help you tackle any issues faced:
Regards,
Tushar

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by