Find and Replacing a string with a numerical value in ragged array (Mathematica) -


i have gaussian .cube file (http://paulbourke.net/dataformats/cube/) , looking find , replace "nan" string within file numerical value. importing .cube file gives me ragged array structure both string , numerical values. have option import file list of lists.

i have tried replaceall command, mathematica seems unable find nan string replace it. defined initial array "cubefile":

newcubefile = cubefile /. "nan" -> 1000000 

the same goes replacepart command.

an example of (shortened) .cube file 2 nan values want replace:

{" grad_cube", " 3d plot", " reduced density gradient", "   10    \ 0.000000    0.000000    0.000000", "   45    0.711111    0.000000    \ 0.000000", "   45    0.000000    0.711111    0.000000", "   45    \ 0.000000    0.000000    0.711111", "   6  0.0   0.000000   0.000000   \ 0.000000", "   8  0.0   0.636571  29.627942  31.998664", "   1  0.0   \ 2.452233  29.435574  31.997116", "   8  0.0   1.419780   1.757082  \ 31.998335", "   1  0.0  29.967743   0.233347   0.002315", "   1  0.0  \  4.896759   1.786080  31.998626", "   8  0.0   6.712387   1.593495  \ 31.999036", "   6  0.0   7.348967  31.221446  31.999373", "   8  0.0  \  5.928984  29.464534  31.999015", "   1  0.0   9.381256  30.988384   \ 0.000684", "  0.10000e+03  0.10000e+03  0.10000e+03  0.10888e+01  \ 0.16636e+01  0.24435e+01", "  0.35378e+01  0.50957e+01  0.73141e+01  \ 0.10460e+02  0.14902e+02  0.21154e+02", "  0.29923e+02  0.42194e+02  \ 0.59323e+02  0.83185e+02  0.11637e+03  0.16246e+03", "  0.22639e+03  \ 0.31515e+03  0.43757e+03  0.55223e+03  0.41025e+03  0.41014e+03", "  \ 0.55221e+03  0.43755e+03  0.31514e+03  0.22639e+03  0.16245e+03  \ 0.11637e+03", "  0.83184e+02  0.59323e+02  0.42194e+02  0.29924e+02  \ nan nan"} 

how go doing this?

thank all.

try

   stringreplace[#, "nan" -> "0.0"] & /@ list 

where list show above.

mathematica graphics


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -