griddedInterpolant bug with Matlab Coder in R2022b
Show older comments
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 Comment
Sri Raman A
on 10 Nov 2022
Accepted Answer
More Answers (1)
Steven Lord
on 10 Nov 2022
0 votes
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 Comments
Sri Raman A
on 10 Nov 2022
Steven Lord
on 10 Nov 2022
My first thought would be to try to reshape the arrays into vectors, call griddedInterpolant with those vectors of query points, and reshape them back into arrays. But I have not tried to generate code from the code you posted with that modification so I'm not 100% sure that this will not cause difficulties for MATLAB Coder.
You may wish to send your original code to Technical Support directly using the Contact Support link under the Get Support heading at the end of this page and work with the Support staff to determine the best approach for generating code from it. There is no guarantee that suggestions we make for your simplified code posted in this discussion will generalize to your larger and presumably more complicated code.
Sri Raman A
on 10 Nov 2022
Sri Raman A
on 10 Nov 2022
Steven Lord
on 10 Nov 2022
If you want an official Technical Support answer, please contact Technical Support directly using the Contact Support link under the Get Support heading at the end of this page.
Sri Raman A
on 10 Nov 2022
Sri Raman A
on 10 Nov 2022
Sri Raman A
on 10 Nov 2022
Steven Lord
on 10 Nov 2022
If you contact the Technical Support staff you can speak to people with more experience with MATLAB Coder than I have. I don't know whether or not the second error message you posted is the result of a bug.
Torsten
on 10 Nov 2022
Most of the people in this forum do not belong to Mathworks staff. I can understand that you are frustrated, but I wonder why you deposit your frustration here.
Do as Steven Lord says: Contact the Technical Support. The people there get their money to help you.
Sri Raman A
on 10 Nov 2022
Walter Roberson
on 11 Nov 2022
"If there is no bug - why dont the support staff point me to an example which explains the problem"
Perhaps because there are no support staff reading this Question? Bruno and Torsten do not work for Mathworks at all, and Steven Lord is not support staff. Steven Lord is here as a volunteer — an activity that he does not get paid for. I do not recall quite what his job is, but I recall that he is not support staff, and that he does not use the compiler tools much in his job.
Sri Raman A
on 11 Nov 2022
Sri Raman A
on 16 Nov 2022
Walter Roberson
on 17 Nov 2022
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.)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!