Regarding Interpolation( vertical)

I have two data sets in which one is 4D data sets and another one is 2D.
1) first data: 120( longitude) x 90(latitude) x 34 (vertical level) x 8 (Time) 2) second data: 15( vertical level) x 469( number of observations)
I would like to interpolate 34 vertical levels to 15 vertical levels. so somebody knows how to fix this problem?

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 7월 18일

1 개 추천

A = rand(5,5,34,5);
[ii jj kknew LL] = ndgrid(1:5,1:5,linspace(1,34,15),1:5);
C = interpn(A,ii,jj,kknew,LL);
You could just use interpn directly, thought this will use information from other dimensions.

댓글 수: 4

Uday
Uday 2011년 7월 18일
Thanks for answer but still I have one question ,
A=rand(5,5,34,5), but in my case , A=(120,90,34,8). I always get message that "Matrix dimensions must agree".
and the dimensions A(120 x 90 X 34(1:34) x 8 & (15 (1:15) X 469)
Sean de Wolski
Sean de Wolski 2011년 7월 18일
I just did that as an example since I didn't want to kill the RAM on my laptop. For your case:
[ii jj kknew LL] = ndgrid(1:120,1:90,linspace(1,34,15),1:8);
C = interpn(A,ii,jj,kknew,LL);
Also, how do you plane on comparing a 2d matrix 15x469, to a 4d matrix? I think bsxfun/repmat might be necessary. Or do you want to append it?
I.e.
cat(3,A,C)? (in which case you don't even need to interpolate down?
Please clarify the goal.
Uday
Uday 2011년 7월 19일
Actually I have two different data-sets 1) 4D data (120(longitude) X 90(latitude) x 34( pressure levels) x 8 (time)), 2) 2D 15( number of vertical levels) x 469 ( number of observations those varies always). My main objective to interpolate vertical levels of two data-sets ( which is 34 & 15). so for this first of all I need to get 15 levels from 4D data. I tried with 4D data-sets the method which you have mentioned earlier, but I got error "Undefined function or method 'colon' for input arguments of type 'double' and attributes 'full 4d real".
Sean de Wolski
Sean de Wolski 2011년 7월 19일
Show us _exactly_ what you wrote.

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

Andrei Bobrov
Andrei Bobrov 2011년 7월 18일

0 개 추천

In = DataInput; % Array 4D
[a b oldc d] = size(In);
newc = 15;
Out = zeros([a b newc d]);
for j4 = 1:d
d1 = reshape(permute(In(:,:,:,j4),[3 2 1]),oldc,[]);
Out(:,:,:,j4) = permute(reshape(cell2mat(arrayfun(@(i1)interp1((1:oldc)',d1(:,i1),linspace(1,oldc,newc)'),1:a*b,'un',0)),newc,b,a),[3 2 1]);
end

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2011년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by