2-d interpolation in matlab

조회 수: 5 (최근 30일)
Prerna Mishra
Prerna Mishra 2022년 10월 16일
편집: Torsten 2022년 10월 16일
I have a matrix v0 nd*nk*na, which depends on values of d, k and a. I want to interpolate the matrix v for values of d and k which are stored in dvec and kvec and range from dmin to dmax and kmin and kmax respectively. I tried to use interp2d as follows:
g = interp2(kvec,dvec,v0,k,d,'linear');
I get this error:
Error using .'
TRANSPOSE does not support N-D arrays. Use PAGETRANSPOSE/PAGECTRANSPOSE to transpose pages or PERMUTE to reorder
dimensions of N-D arrays.
Is there any way to fix this?
  댓글 수: 5
Prerna Mishra
Prerna Mishra 2022년 10월 16일
I see. But is there any way to do the problem that I have? Keeping the a dimension constant, can I interpolate the value of v0 for d and k?
John D'Errico
John D'Errico 2022년 10월 16일
@dpb has given you the correct answer, where I was being too lazy to go. ;-)
Effectively, you need to treat this as a 3-dimensional interpolation. Or you can extract each plane of v0, and then use a 2-d interpolation along that plane, thus for each possible a.

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2022년 10월 16일
As per usual, would be far easier to visualize what you're after if would provide a (smallish) sample dataset.
But, if by " Keeping the a dimension constant, ..." you mean interpolating over the other two dimension at a given plane of the 3D array, then sure -- just pass the desired plane into the interp2d call...
ixa=... % a specific plane of 3D array v0 in range 1:size(v0,3)
g = interp2(kvec,dvec,v0(:,:,ixa),k,d,'linear');
Alternatively, coding may be simpler to just use interp3 even if the 3rd dimension interpolated value is constant.
g=interp3(kvec,dvec,avec,v0,k,d,a,'linear');
Nothing says a can't be a single value.
  댓글 수: 9
Prerna Mishra
Prerna Mishra 2022년 10월 16일
Right, I understood that. The problem is that when I interpolate using the code above, I get g which is a scalar. I should have ideally gotten a 7 * 1 vector.
For example in an easier problem say:
v0 = rand(100,3);
kv = 1:100;
g = interp1(kv,v0,1.5,'linear')
The output of interpolation is 3*1.
I was expecting similar for this 3 - dimensional problem. That the output of the interpolation should be na*1 vector and not a scalar.
Torsten
Torsten 2022년 10월 16일
편집: Torsten 2022년 10월 16일
Let the result of the interpolation be whatever it is, but in the end, "val" must be a scalar.
If g is a vector of the same size as prob(j,:), g*prob(j,:).' gives a scalar - so this would work.
Since we all don't know what you are doing in your code, we can only point out the mistakes, but cannot give advice on how to change your code adequately.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by