문제

one probably easy question that I for some reason cannot see the answer to:

I am working on a Matlab Project where I need to interpolate a specific set of data. I have a 2D-Matrix MAT and two Vectors X and Y that assign a value to each column and row (strictly monotonically increasing of course). The Matrix is mostly 0s, except for some diagonal lines amongst which it has nonzero values.

I now wish to interpolate the data along thise lines over the entire area, a linear Interpolation should be enough for now. My approach is

[y,x] = meshgrid(Y,X); %Create a Meshgrid out of the grid vectors
ySave=y;xSave=x;
M = MAT;
%Now, we eliminate the Elements where MAT is 0 since we want to interpolate there
y(MAT==0)=[];
x(MAT==0)=[];
M(MAT==0)=[];
interpolant = scatteredInterpolant(y',x',M'); % and we create our Interpolant
result = interpolant(ySave,xSave);

However, when I execute this code, the interpolated Picture not only does not resemble the "intuitive" interpolation at all - it does not even have the original data points included... what am I doing wrong?

Thanks for the help!

Edit from Comments, for visibility: imgur.com/a/7baxM This is the visual respresentation of the data. Top picture is the interpolated result, bottom one the input data. There are no values close to zero, and as you can tell, the pictures are far from similar. It looks a bit like the correct interpolation got streched weirdly or something...

도움이 되었습니까?

해결책 2

Alright, I figured it out. For some weird reason, it works as intended with

[y,x] = meshgrid(X,Y);

I am still trying to understand where the coordinates could have gotten mixed up, but at least now the code works. Thanks to those who tried to help!

다른 팁

You have a series of 1d interpolation problem -- interpolating intensity values s along those lines. Rotate your data first to align the lines with the x-axis for example, then ask Matlab to 1d interpolate over the scattered points (x_i, s_i)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top