2-d interpolation in matlab

3 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by