Interpolation of 3D scattered data to 3D graph in Simulink

1 view (last 30 days)
My experimental data x,y,z are 1*m matrices.
And I want to make 3D graph of f(x,y,z).
I saw the way of using griddata3 and meshgrid, but I have a problem.
I made random scale 1*m matrices xi,yi,zi using MATLAB function like this.
function xl=fcn(~)
xl = linspace(-10,10,200);
And I made v to use griddata3 like this.
function v = fcn(xl,yl,zl) v = griddata3(xl,yl,zl);
Then, there was a error that I can't use griddata3.
The function 'griddata3' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation. Function 'MATLAB Function3' (#200.32.41), line 3, column 5: "griddata3" Launch diagnostic report.
I changed it using coder.extrinsic, but there was another error.
function v = fcn(xl,yl,zl)
coder.extrinsic('griddata3')
v = griddata3(xl,yl,zl);
Function output 'v' cannot be an mxArray in this context. Consider preinitializing the output variable with a known type.
Function 'MATLAB Function3' (#200.0.80), line 1, column 1: "function v = fcn(xl,yl,zl)" Launch diagnostic report.
I changed like this.
function v = fcn(xl,yl,zl)
coder.extrinsic('griddata3')
v=zeros(200,200,200);
v = griddata3(xl,yl,zl);
Another error
MATLAB Function Interface Error: Error calling generated SFunction, untitled2_sfun. Invalid MEX-file 'C:
What should I do now? Am I right from this phase?

Answers (1)

Mike Hosea
Mike Hosea on 21 Sep 2012
What version of MATLAB are you using? This will help me figure out what to do. Note that the function griddata3 no longer exists in R2012b. One is supposed to use griddata instead. The invalid mex file error is probably because a 200-by-200-by-200 array is not going to work with static memory allocation (61 megabytes). You'll need to have dynamic memory allocation enabled for sure.
  2 Comments
Byeonguk
Byeonguk on 21 Sep 2012
Edited: Byeonguk on 21 Sep 2012
I use R2011b. And am I doing right to make graph? Are there more easy ways to make graph using Simulink?
K E
K E on 21 Sep 2012
If it is OK to plot the data after the simulation is complete, I would export it to the workplace using the To Workspace block. Then you can use griddata etc from within Matlab rather than in Simulink. And if you just need to plot the datapoints without interpolation, use plot3.

Sign in to comment.

Categories

Find more on Interpolation 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!