I cannot use interp2 function instead of griddata

조회 수: 13 (최근 30일)
Serhat Sarihan
Serhat Sarihan 2024년 12월 6일
댓글: Matt J 2024년 12월 8일
I have a dynamic model as a MATLAB script that uses griddata function for interpolation. When I tried to implement the same model in Simulink, the only way I could use griddata was by using Matlab Function Block with coder.extrinsic('griddata') command inside. After that the Simulink model was working fine but when I tried generate a code from that model it was not possible due to griddata does not have the C/C++ Code Generation Capability. After some research, I figured out that I could use interp2 function as an alternative which has the extended capability of C/C++ Code Generation. However, when I tried to use it I got an error says; 'Grid arrays must have NDGRID structure.'
Here, a sample data extracted from my dynamic model is given with griddata and interp2 functions.
clear, clc;
% sample data
x = [1.1390, 1.1069, 1.0868;
0.6763, 0.5188, 0.2399;
0.8110, 0.1311, -0.5368;
1.2953, 0.7618, 0.3221;
1.1390, 1.1069, 1.0868];
y = [0, 0, 0;
0.1640, 0.4879, 0.8118;
0.0000, 0.0000, 0.0000;
-0.1640, -0.4879, -0.8118;
-0.0000, -0.0000, -0.0000];
v = [0, 0, 0;
0.1352, 0.2279, 0.6906;
0.0417, 0, 0.5807;
0, 0.1010, 0.4709;
0, 0, 0];
xq = [0.2000, 0.5950, 0.9900;
0.0000, 0.0000, 0.0000;
-0.2000, -0.5950, -0.9900;
-0.0000, -0.0000, -0.0000;
0.2000, 0.5950, 0.9900];
yq = [0, 0, 0;
0.2000, 0.5950, 0.9900;
0.0000, 0.0000, 0.0000;
-0.2000, -0.5950, -0.9900;
-0.0000, -0.0000, -0.0000];
% griddata function
vq = griddata(x,y,v,xq,yq,'cubic');
% interp2 function
Vq = interp2(x,y,v,xq,yq,'cubic');
I would like to get the same result using either interp2 function or any other function that has the C/C++ Code Generation Capability. Then I would be able to use it for code generation.
  댓글 수: 3
Stephen23
Stephen23 2024년 12월 6일
편집: Stephen23 2024년 12월 6일
"I cannot use interp2 function instead of griddata"
Correct: your data are not gridded, therefore you cannot use INTERP2.
Serhat Sarihan
Serhat Sarihan 2024년 12월 6일
Thank you for your responses. I will try to solve this issue by the help of those links you've shared.
Note: The code I shared is a dummy script for generating data to a sample point of my dynamic model. The original code is old and written by another person. I was trying to make use of it to create a dynamic model and made some modifications to it for that purpose. This was the part I did not understand.

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

답변 (1개)

Matt J
Matt J 2024년 12월 7일
scatteredInterpolant is supported for Code Generation as of R2024b, so if you can upgrade from R2019b, that might sove it.
  댓글 수: 2
Serhat Sarihan
Serhat Sarihan 2024년 12월 7일
Thank you for this advise Matt.
After making some adjustments on my model to use scatteredInterpolant properly I should upgrade my Matlab version as you suggest.
Matt J
Matt J 2024년 12월 8일
You're welcome, but if this resolves your question please Accept-click the answer.

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

카테고리

Help CenterFile Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by