From: Matt J on 25 Jun 2010 12:35 "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i02ar8$7on$1(a)fred.mathworks.com>... > > %A hint; if you're still looking. > A = cat(3,ones(3),2*ones(3),3*ones(3)); > [xold yold zold] = ndgrid(1:3,1:3,1:2:5); > [xnew ynew znew] = ndgrid(1:3,1:3,1:5); > > griddata3(xold,yold,zold,A,xnew,ynew,znew) ============== This will be quite slow in higher dimensions. Because MATLAB's interpolation functions are rather slow, it is probably best to do this upsampling by sparse matrix multiplication (or get a faster interpolation routine from the FEX). Below is a speed comparison of the method Bruno described using interp1 (in a duplicate thread) to essentially the same method replacing interp1 by a sparse matrix multiplication. U=rand( 120,100,100); %Method interp1 tic; p = size(U,3); Unew = permute(U,[3 1 2]); Unew = interp1(1:p,Unew,1:0.5:p); Unew = ipermute(Unew,[3 1 2]); toc; %Elapsed time is 0.340892 seconds. %Method: sparse matrix tic; [nx,ny,N]=size(U); A=[speye(N),spdiags(ones(N,2),-1:0,N,N-1)/2]; A(:,[1:2:end,2:2:end])=A; A=A.'; p = size(U,3); Unew = reshape(U,[],p).'; Unew = A*Unew; Unew2=reshape(Unew.',nx,ny,[]); toc; %Elapsed time is 0.067520 seconds. Also, as i;llustated below you can abbreviate the syntax of the sparse matrix approach using my KronProd tool http://www.mathworks.com/matlabcentral/fileexchange/25969-efficient-object-oriented-kronecker-product-manipulation You can also save the KronProd object for later reuse on arrays of the same size. Z=KronProd({1,1,A},[1,2,3],[nx,ny,N]); %make KronProd object tic; %Assume KronProd object has been saved previously for reuse Unew=Z*U; toc; %Elapsed time is 0.042638 seconds. |