Converting from griddata3 to TriScatteredInterp
2 views (last 30 days)
Show older comments
Hi I need help converting a line in my code to TriscatteredInterp.
This is the original line:
ReconstructedUS(:,:,bg:en) = griddata3(TGridX, TGridY, TGridZ, US, RegularGridX, RegularGridY, RegularGridZ, 'linear');
I tried converting to TriscatterInterp using:
F = TriScatteredInterp(TGridX(:,:,:), TGridY(:,:,:), TGridZ(:,:,:), US(:,:,:), 'linear');
ReconstructedUS(:,:,bg:en) = F(RegularGridX, RegularGridY, RegularGridZ);
However I keep getting the error that the dimensions are in an invalid space.
Any help?
0 Comments
Answers (2)
Walter Roberson
on 8 Nov 2011
Notice in the documentation,
F = TriScatteredInterp(X, V) creates an interpolant that fits a surface of the form V = F(X) to the scattered data in (X, V). X is a matrix of size mpts-by-ndim, where mpts is the number of points and ndim is the dimension of the space where the points reside (ndim is 2 or 3). The column vector V defines the values at X, where the length of V equals mpts.
But your TGridX is three dimensional, which is not a two dimensional array of size mpts x 2 or mpts x 3
So:
F = TriScatteredInterp( [TGridX(:), TGridY(:), TGridZ(:)], US(:), 'linear');
4 Comments
Walter Roberson
on 8 Nov 2011
I do not see any particular reason why you have bg and en in your ReconstructedUS array indices, but presumably it relates to the code you used to select the data.
I have no idea what the performance difference is between interp3 and TriscatteredInterp. My naive expectation would be that interp3 would be faster as it does not need to search to track which vertices are closest in order to do the interpolation.
When I saw your question I assumed it had to do with the question earlier today from someone whose data was not quite regular, but that turns out to be a different author: http://www.mathworks.com/matlabcentral/answers/19607-interp3-problem
Aman
on 9 Nov 2011
2 Comments
Walter Roberson
on 9 Nov 2011
"a double array" means an array of datatype double precision. What data class are your TGrid* and US ?
See Also
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!