How to interpolate between matrices over time?

조회 수: 8 (최근 30일)
Aviad
Aviad 2014년 9월 30일
편집: SK 2014년 10월 2일
Hi all, I have 20 matrices, each of the size 128X128X128. Each matrix contains the temperatures in space, and every matrix is in different time. I want to found out for each pixel on what time the temperature was 10, so I want to get 128X128X128 matrix contains the time when the temperature in that pixel was 10. Of course I can do 128^3 interpolations, but I want it to be efficient.

채택된 답변

SK
SK 2014년 9월 30일
편집: SK 2014년 9월 30일
To complete the last interpolation bit, it is as simple as:
R = (M(linhi) - 10)./(M(linhi) - M(linlo));
pixtimes = (1-R).*Time(IXlo) + R.*(Time(IXhi)-Time(IXlo));
pixtimes = reshape(pixtimes, [128, 128, 128]);
Takes under 1 second on my machine.
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2014년 10월 1일
편집: Sean de Wolski 2014년 10월 1일
Loop over all of them and solve the zero finding problem at each point.
SK
SK 2014년 10월 2일
편집: SK 2014년 10월 2일
ALternatively, If T is your matrix of pixel temperatures (128 x 128 x 128), instead of doing
Blo = M < 10;
you could do:
T = transpose(T(:));
T = ones(20,1)*T;
M = M(:,:)
Blo = (M < T);
Bhi = (M >= T);

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

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2014년 9월 30일
편집: Sean de Wolski 2014년 9월 30일
Well you could do 128^3 optimization problems too. I don't see any reason why you can't do this with interp1.
x = rand(128,128,128,10); % simulate your data stacked in the 4th dimension - time
v = permute(x,[4 1 2 3]); % first dimension is the one we interpolate over
tic
% Do the interpolation
vv = interp1(1:10,v,1:0.05:10);
toc
% permute back so time is 4th dim
vfinal = ipermute(vv,[4 1 2 3]);
On my laptop it's taking about 8s.
Of course this only interpolates to that resolution. If you need better, it might make sense to solve this with fzero for each 128^3 voxel in time. The objective function would be using interp1 on those 10 points. Let me know if this approach interests you.

SK
SK 2014년 9월 30일
편집: SK 2014년 9월 30일
I misunderstood your problem the first time thinking that you wanted to find the temperature at time 10. But you want it the other way around - the time at which the temperature was 10. That is a little tricky
They may be more than one such time for each pixel, no? In that case do you want both times, only the first ...? Anyway supposing that there is exactly one and only one such time, you could do (Assuming that your matrices have been put into 4-D form (20x128x128x128):
M = M(:,:);
Blo = (M < 10);
Bhi = (M >= 10);
[~, J] = max(Blo(end:-1:1, :));
IXlo = 20 - J + 1;
[~, IXhi] = max(Bhi);
N = 128^3;
linlo = 20*(0 : N-1) + IXlo;
linhi = 20*(0 : N-1) + IXhi;
Now linlo contains the linear indices of M of the last temp that is < 10. linhi contains the linear indices in M of the first temp that is >= than 10. Then, assuming that you have the 20 times in a vector, say:
Time = 0.5 : 0.2 : 4.3;
you can do a simple linear interpolation of the 'Time' vector between M(linlo) and M(linhi) to get the N times in a long vector (call it say pixtimes) of length N. Then reshape pixtimes into 128x128x128.

카테고리

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