Prev: Size of the picture
Next: convert 3D matrix into 2D
From: Pinpress on 4 Feb 2010 22:57 Hi, I need to interpolate multiple YI values using: YI(:,i) =griddata(X,Y(:,i), XI); Instead of performing griddata N times in a for loop, is there a better/faster way? It seems that internally "dsearchn" would be unnecessarily executed multiple times. Any input is appreciated!
From: John D'Errico on 5 Feb 2010 00:13 "Pinpress" <nospam__(a)yahoo.com> wrote in message <hkg4uh$otc$1(a)fred.mathworks.com>... > Hi, > > I need to interpolate multiple YI values using: > > YI(:,i) =griddata(X,Y(:,i), XI); > > Instead of performing griddata N times in a for loop, is there a better/faster way? It seems that internally "dsearchn" would be unnecessarily executed multiple times. Any input is appreciated! Easiest is just to do the interpolation yourself. Something like this: % 2-d data (independent variables) n = 100; X = rand(n,2); % 10 dependent variables (I'm not very creative % here about the actual function. Too bad.) m = 10; Y = rand(n,m); % do a triangulation of your own tri = delaunayn(X); % some points to interpolate Xint = rand(500,2); [Tin,bcc] = tsearchn(X,tri,Xint); K = ~isnan(Tin); Yint = zeros(size(Xint,1),m); for i = 1:3 Yint(K,:) = Yint(K,:) + bsxfun(@times,bcc(K,i),Y(tri(Tin(K),i),:)); end Yint(~K,:) = NaN; HTH, John
From: Pinpress on 5 Feb 2010 11:11 Thanks, John. I ended up editing the Matlab built-in griddatan.m, and made some very minor changes and now it should work for multiple columns of Y. "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hkg9cu$nq3$1(a)fred.mathworks.com>... > "Pinpress" <nospam__(a)yahoo.com> wrote in message <hkg4uh$otc$1(a)fred.mathworks.com>... > > Hi, > > > > I need to interpolate multiple YI values using: > > > > YI(:,i) =griddata(X,Y(:,i), XI); > > > > Instead of performing griddata N times in a for loop, is there a better/faster way? It seems that internally "dsearchn" would be unnecessarily executed multiple times. Any input is appreciated! > > Easiest is just to do the interpolation yourself. > Something like this: > > % 2-d data (independent variables) > n = 100; > X = rand(n,2); > > % 10 dependent variables (I'm not very creative > % here about the actual function. Too bad.) > m = 10; > Y = rand(n,m); > > % do a triangulation of your own > tri = delaunayn(X); > > % some points to interpolate > Xint = rand(500,2); > > [Tin,bcc] = tsearchn(X,tri,Xint); > K = ~isnan(Tin); > Yint = zeros(size(Xint,1),m); > for i = 1:3 > Yint(K,:) = Yint(K,:) + bsxfun(@times,bcc(K,i),Y(tri(Tin(K),i),:)); > end > Yint(~K,:) = NaN; > > HTH, > John
From: Loren Shure on 8 Feb 2010 08:55 In article <hkhfuo$ec4$1(a)fred.mathworks.com>, nospam__(a)yahoo.com says... > Thanks, John. I ended up editing the Matlab built-in griddatan.m, and made some very minor changes and now it should work for multiple columns of Y. > You would be better off editing the file and saving it elsewhere under a new name. That way, if you update MATLAB, you won't lose your modifications. -- Loren http://blogs.mathworks.com/loren
|
Pages: 1 Prev: Size of the picture Next: convert 3D matrix into 2D |