Prev: Help in patch command ...
Next: Fault signal
From: Michael Snyder on 7 Jun 2010 10:50 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <huivka$e2u$1(a)fred.mathworks.com>... > "Michael Snyder" <sirzerp(a)mathworks.com> wrote in message <huiulq$75v$1(a)fred.mathworks.com>... > > Hi Y'all, > > > > I am working with a large 4D matrix using many iterations to solve a problem. > > > > My problem is once in a while my matrix operations produce a non-number, inf, -inf, or even an nan. There is no easy way to know ahead of time when this happens. > > > > I am looking for the fastest possible way to convert the non-numbers to zeros between iterations. If I convert the non-numbers to zeros between iterations then it does not effect my final results. > > > > I have gotten my main iteration loop down to 1.5 seconds. If I use the following code to convert non-numbers to zeros, it adds 2.7 seconds to my loop. This isn’t good. I have tried converting my 4D matrix to 3D matrixes, but it doesn’t speed up my code in this case > > > > maxtrix_out(maxtrix_out==Inf)=0; > > maxtrix_out(maxtrix_out==-Inf)=0; > > maxtrix_out(maxtrix_out==NaN)=0; > > > > There has to be a faster way. Can anyone point me in the right direction? > > Well, actually, you are wasting some time here. > Try this test... > > >> nan == nan > ans = > 0 > > Instead, read these. > > help isnan > help isinf > > matrix(isnan(matrix) | isinf(matrix)) = 0; > > John Hi John, On the other hand, I tried the command on a 3d matrix and it came in at .2 seconds. Which is much better than before. Thanks, Michael
From: dpb on 7 Jun 2010 11:15
Walter Roberson wrote: .... > The most direct way (though I do not promise it is the fastest > available) would be .... I'd think that would be to not generate them in the first place... :) Altho would need more info to see if that's reasonable, obviously. -- |