griddedInterpolant bug with Matlab Coder in R2022b

8 次查看(过去 30 天)
Hi All,
I am trying to make use MATLAB Coder (version 5.5) for griddedInterpolant, But I am getting the following errors
"??? Sample points must be 1-dimensional for code generation."
clearvars; clc; close all;
x = -5:0.8:5;
y = -5:0.8:5;
[xg,yg] = ndgrid(x,y);
vg = sin(xg.^2 + yg.^2) ./ (xg.^2 + yg.^2);
surf(xg,yg,vg); hold on
xq = -4;
yq = 1.2;
vq = griddedInterpolant_test(x,y,xq,yq);
plot3(xq,yq,vq,'r*');
codegen -report -config:lib griddedInterpolant_test.m -args {-5:0.8:5, -5:0.8:5, -4, 1.2}
In my original code, I also get the following error even though xg, yz, zg matrices in griddedInterpolant(xg,yg,zg) are all having a fixed (m x n) size and when the interpolant is evaluated at a single xq, yq.
"??? Unable to determine varargin/varargout index due to failed loop unrolling."
Does it mean that MATLAB Coder is not compatible with 2-dimensional interpolation when griddedInterpolant is used ?
Please write to me if you need any additional details
  1 个评论
Sri Raman A
Sri Raman A 2022-11-10
vg is generated inside the griddedInterpolant_test function based on the same xg and yg. It is additionally generated in the script only for plotting the surface (because visualizing the problem makes it easy to understand)

请先登录,再进行评论。

采纳的回答

Thomas Best
Thomas Best 2023-8-8
编辑:Thomas Best 2023-8-8
I had the same error - updating to R2023a fixed it for anyone else running into the same problem.

更多回答(1 个)

Steven Lord
Steven Lord 2022-11-10
The first error you received is not a bug. The fact that griddedInterpolant requires that the sample points be vectors rather than matrices or N-dimensional arrays when used in code generation with MATLAB Coder is a documented limitation. See the "C/C++ Code Generation" item in the Extended Capabilities section of the documentation page to which I linked above.
I am not certain of the reason you received the second error message you quoted. From the fact that you said you received this with "my original code" I assume that you ran a different code than the one you posted to receive that error. Without seeing that code I'm not sure if it would be possible to determine the cause of this error.
  16 个评论
Sri Raman A
Sri Raman A 2022-11-16
For those who are interested, Here is the reply (for case number 05848451) from MATLAB Technical support on this.
"griddedInterpolant supports only 1D inputs for code generation as of R2022b, we'll enable support for 2D and nD inputs only in the next release.
Enabling 2D inputs requires significant changes, that can't be implemented in R2022b"
And they have set the current status of my case to Bug/Enhancement Submitted
Walter Roberson
Walter Roberson 2022-11-17
If you are commenting in the Answers section for a technical query - then I expect the answers to be technical and leading to a solution for the problem I have posted. In short I expect bulls-eye kind of technical answers
Well, that certainly might be what you expect but it is not what this resource was created for.
This MATLAB Answers resource was created for members of the public to ask other members of the public for assistance with Mathworks related topics. It is not an official support forum from Mathworks, and any Mathworks employees who respond here do so as volunteers (with the exception of people running the facility itself.)
Experts in a specialized topic might not happen to see any particular question -- there are between 100 and 200 new Questions per day, and discussion on more than 200 different topics per day even during slow times -- and topic experts are often busy doing other thing.
It is normal and expected here, an inherent part of why the facility was set up, that responses from volunteers might be along the lines of "I don't know for sure, but let us work together to see if we can come up with some solution together."
It also happens a lot of the time that people asking questions do not explain well, or that people turn out to be asking about something different than what they actually need, so it is common that the volunteers end up asking a bunch of questions in order to figure out what is really needed and to figure out what is happening (and try to figure out why, and what the work-arounds might be.)
A lot of the people who ask questions do not have English as their native language, and a fair number of the volunteers do not have English as their native language, so there are also translation issues, and differences in how terms are to be intepreted.
The purpose of the facility is for people doing their best to help other people, not questions to only be responded to by topic specialists who already know the answer or can definitely find out (such as by having access to internal source code.)

请先登录,再进行评论。

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by