[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Applying masks on matrices with Nan/Inf on them
From: |
Joao Cardoso |
Subject: |
Applying masks on matrices with Nan/Inf on them |
Date: |
Thu, 18 Feb 1999 13:44:32 +0000 |
Hi,
How can I apply a mask to a matrix that has NaNs or Inf on it?
For ordinary real numbers, I can do:
octave:122> a=rand(3)
a =
0.439150 0.426345 0.834121
0.711628 0.927248 0.055622
0.091911 0.265919 0.239936
octave:123> (a>0.5) .* a
ans =
0.00000 0.00000 0.83412
0.71163 0.92725 0.00000
0.00000 0.00000 0.00000
but as any operation on Nan or Inf retuns a Nan or Inf,
octave:124> a(2,3)=nan
a =
0.439150 0.426345 0.834121
0.711628 0.927248 NaN
0.091911 0.265919 0.239936
octave:125> (!isnan(a)) .* a
ans =
0.439150 0.426345 0.834121
0.711628 0.927248 NaN
0.091911 0.265919 0.239936
Is the bellow approach the only one? I don't like to change defaults in
my scripts...
octave:130> do_fortran_indexing = 1;
octave:131> a(find(isnan (a)))= 0
a =
0.43915 0.42634 0.83412
0.71163 0.92725 0.00000
0.09191 0.26592 0.23994
Thanks,
Joao
--
Joao Cardoso | e-mail: address@hidden
INESC, R. Jose Falcao 110 | tel: + 351 2 2094322
4050 Porto, Portugal | fax: + 351 2 2008487
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Applying masks on matrices with Nan/Inf on them,
Joao Cardoso <=