I tried to plot a surface in MATLAB but, since it is the first time I had to do something like this, I need a confirmation on the process I followed because it is important for my project to plot the right surface.
I have 3 vectors obtained from measurement data: $x$ (displacement), $v$ (velocity) and $p$ (force). The goal is to plot a surface where $x$ and $v$ represent a point in the plane and $p$ is the "height" above that plane. The idea is to have a quite smooth surface, because then I have to fit this surface created from measurement data using a mathematical model.
This is what I have done:
first I create the grid: (since my measurements vectors have more than 400000 samples, do I have to use more than 1000 for x_plot
and y_plot
to have a good plot? I have also a problem when I increase too much the length of x_plot
and y_plot
, infact I get an "out of memory"
error message)
x_plot = linspace(min(x),max(x),1000);
y_plot = linspace(min(v),max(v),1000);
[XI,YI] = ndgrid(x_plot,y_plot);
Then I create the scattered data interpolant:
F = TriScatteredInterp(x,v,p,'natural');
And now I evaluate the interpolant on the grid:
ZI = F(XI,YI);
Finally I plot the surface:
figure()
mesh(XI,YI,ZI)
Is this the right method?
Is it better to use ndgrid or meshgrid to create the grid?