My question is about using griddata as a substitute for interp2 in matlab as my data is not monotonic. I have extracted data for x_measured, y_measured, z_measured and would like to interpolate z at specified Points (x,y).
This code works:
z = griddata(x_measured,y_measured, z_measured,x,y,'linear')
This obviously doesn't as the data is non monotonic:
z = interp2(x_measured,y_measured, z_measured,x,y,'linear')
I'm wondering why griddata works. griddata returns a value using linear Interpolation as specified in the function call. Is there a fundamental difference between the two algorithms?
Related
I'm trying to interpolate a 3D vector field. For every (x,y,z) position we have a vector (u,v,w). I have another set of points let's call them (xq,yq,zq) in which I don't have vector information (uq,vq,wq). I would like to interpolate my data to find the vectors at the points (xq,yq,zq).
I've tried to interpolate using several functions like griddata, by interpolating each vector component individually.
uq = griddata(x,y,z,u,xq,yq,zq);
vq = griddata(x,y,z,v,xq,yq,zq);
wq = griddata(x,y,z,w,xq,yq,zq);
I expect to obtain the vectors at the locations I specified, but the message I get is:
"Warning: The underlying triangulation is empty - the points may be
coplanar or collinear."
Is there a better way to interpolate a vector field?
I am experimenting with the mexopencv project that allows using the
OpenCV library from MATLAB .m files in order to compare the performance
of the native MATLAB functions with the OpenCV functions
I would like to substitute a call to the MATLAB interp2 function:
Vq = interp2(X,Y,V,Xq,Yq) returns interpolated values of a function of two variables at specific query points using linear interpolation. The results always pass through the original sampling of the function. X and Y contain the coordinates of the sample points. V contains the corresponding function values at each sample point. Xq and Yq contain the coordinates of the query points.
The substitute shall be a call to the cv.remap function.
Applies a generic geometrical transformation to an image
dst = cv.remap(src, map1, map2)
dst = cv.remap(src, map1)
dst = cv.remap(..., 'OptionName',optionValue, ...)
The three SO questions Similar OpenCV Api for interp2 in Matlab,
How to do grid interpolation interp2 in OpenCV
and cv::remap (in opencv) and interp2 (matlab)
state that the OpenCV function remap can be used instead of the native MATLAB
function interp2, but I have no idea how-to correctly interpret/transform the
arguments (I have no experience regarding MATLAB and computer vision).
How can I use the mexopencv function cv.remap to get the same effect as if one
would call Vq = interp2(X,Y,V,Xq,Yq)?
I have plotted a piece-wise defined continuous linear function comprising of several oblique straight lines joined end-to-end:-
x=[0,1/4,1/2,3/4,1];
oo=[1.23 2.31 1.34 5.69 7] % edit
y=[oo(1),oo(2),oo(3),oo(4),oo(5)];
plot(x,y,'g--')
I now wish to sample points from this plot itself, say i want the y corresponding to x=0.89. How to achieve that using Matlab? Is there a special function in-built in Matlab?
Yes, there's a built-in function for that: interp1:
vq = interp1(x,v,xq) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the sample points, and v contains the corresponding values, v(x). Vector xq contains the coordinates of the query points.
[...]
See the linked documentation for further options. For example, you can specify the interpolation method (default is linear), or whether you want to extrapolate (i.e. allow for xq values to lie outside the original x range).
How to plot a 3D figure in MATLAB based on a function like f(x,y,z)=0?
And this complicated function can not be written as z = f(x,y).
f(x,y,z)=sum(a.*exp(sv(:,1)-x).^2+sv(:,2)-y).^2+sv(:,3)-z).^2)-b=0
where a is a known vector, sv is a known matrix, b is a known value. x,y,z are three variables. How to draw this surface in 3D way in matlab?
I just solve this question by this tool from the Matlab File Exchange:
Ezimplot3: implicit 3D functions plotter
your function only contains 1D vectors( I am assuming they are of equal lengths), if summed it will give you a constant; therefore, there is really nothing to plot.
I have a 3D data set representing a grid of photosensors which unfortunately were not steady during use. I have estimated the pdf for the motion of the detector and I want to find the expectation value for each sensor. As I don't want to reflect my pdf (i.e. I want f(t) not f(t-tau)) I don't think I can use the matlab convolve function. Is there a function that will do what I want or should I just get on with it? I've found movavg but it seems to do something else or maybe I just haven't followed it correctly.
Also, as I'm faily new to matlab, from C, I tend to use for loops which I'm aware is not the way to use Matlab. Is there an easy way to convert my 1-D pdf to a 3D matrix that will only operate in one axis (z in this case). Something like repmat(i, j, pdf).
Thanks
The expected value of a pdf is the integral over the product of the grid values and the pdf values at the corresponding grid points.
To integrate over a 3D-Grid, use the Matlab function triplequad (doc). As an example, let us compute the expected x value:
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)
pdfxfun in this call must be a function handle which for any (x,y,z) point it receives should return the product of the pdf value at that point and x. In your case, this could probably be achieved by interpolation over your grid data. I don't know a 3D-interpolation function in Matlab, so probably you have to work on this for yourself. Roughly, what you would do is:
function pdfvalue = pdfinterpolation(x,y,z,Xgrid,Ygrid,Zgrid,pdfdata)
% compute interpolated pdfvalue at (x,y,z) from griddata and pdfdata
Then, pdfxfun above can be defined as anonymous function in the call to triplequad:
pdfxfun = #(x,y,z) x*pdfinterpolation(x,y,z,myxgrid,myygrid,myzgrid,pdfdata)
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)