interp3 problem: the value of the last sampling coordinate is not match.
1 view (last 30 days)
Show older comments
Dear Matlab users
I am currently working on a project that involves using MATLAB's interp3 function to interpolate a profile between two points in a 3D dataset. These points are p1 (labeled as starting_point: x1, y1, z1) and p2 (labeled as mid_point: ,x2, y2, z2). The shape of my 3D dataset, rtdose_imgs, is (512, 512, 371), and it consists of double type values.
I have encountered an issue where the interpolated value at p2 does not match the expected value.
The known value at p2 in rtdose_imgs (coordinates x2, y2, z2) is 42.2477. However, the value obtained at the end of the interpolated profile using interp3 is different from this.
I am seeking help to resolve this discrepancy. Any insights or suggestions on how to correctly interpolate the profile between p1 and p2 would be greatly appreciated.
Thank you in advance for your assistance.
numPoints = 183; % You can change this based on the resolution you need
% Generating linearly spaced points between p1 and p2
xq = linspace(st_point_pad(1), mid_point(1), round(numPoints/2));
yq = linspace(st_point_pad(2), mid_point(2), round(numPoints/2));
zq = linspace(st_point_pad(3), mid_point(3), round(numPoints/2));
sz_rtdose_imgs = size(rtdose_imgs);
[X,Y,Z] = meshgrid(1:sz_rtdose_imgs(1),1:sz_rtdose_imgs(2),1:sz_rtdose_imgs(3));
% [Xq,Yq,Zq] = meshgrid((st_point_pad(1):1:mid_point(1)),(st_point_pad(2):1:mid_point(2)),st_point_pad(3):1:mid_point(3))
% Interpolate the values from the 3D matrix
% doseProfile_init = interp3(rtdose_imgs, x, y, z);
doseProfile_init = squeeze(interp3(X,Y,Z, rtdose_imgs, xq,yq,zq))
2 Comments
Angelo Yeo
on 9 Jan 2024
In order to find the precise cause and solution for the issue you are currently experiencing, I believe that the following additional information would be necessary. If you could provide the following information, it would enable contributors, including myself, to assist you more effectively:
1) Example files and data files that can reproduce the issue
2) Exact steps to reproduce the same problem using the files you provided
Answers (1)
Stephen23
on 9 Jan 2024
Edited: Stephen23
on 9 Jan 2024
"Any insights or suggestions on how to correctly interpolate the profile between p1 and p2 would be greatly appreciated."
You are using MESHGRID and INTERP3, but you should be using NDGRID and INTERPN (and get rid of SQUUEZE).
For an explanation of the difference:
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!