2-d interpolation in matlab
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
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
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 件のコメント
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 Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!