1

Question

In MatLab/Octave, I have the statement x(isnan(x)) = 0. I am porting this over to ILNumerics in C#. I am having trouble finding the ILNumerics equivalent to the MatLab/Octave statement mentioned.

In our case, x is a 2x2 array.

What we've tried

  1. noNaNDataValues = dataValues[ILMath.isnan(dataValues)] = 0.0; where dataValues is an ILArray<double>
  2. We have resorted to standard C# for loops and that works fine. But we would rather use ILNumerics considering how much we've invested in it already.
Community
  • 1
  • 1
Jake Smith
  • 2,332
  • 1
  • 30
  • 68

1 Answers1

2

Just use

x[isnan(x)] = 0;

This is directly equivalent to Matlabs syntax. Your first attempt suggests that you want to seperate non-NaN values from NaNs? If so, please clarify.

user492238
  • 4,094
  • 1
  • 20
  • 26
  • It was a silly mistake on our part. Removing `noNaNDataValues = ...` from the first thing we tried fixed it. The original error was an exception being thrown when trying no access a disposed object. `{"Cannot access a disposed object.\r\nObject name: 'The storage is disposed already. Make sure to follow the ILNumerics documentation at http://ilnumerics.net/GeneralRules.html'."}` – Jake Smith Nov 24 '14 at 18:17