How to fill matrix with NaN in Octave

Also see: How to initialize NaN matrix in octave

If you have a matrix in Octave like

fill_matrix_nan_example.m
A = zeros(2,4)

you can fill it with NaN using

fill_matrix_nan_assignment.m
A(:,:) = NaN

Note that you have to use A(:) = NaN for 1D-matrices. A(:,:) = NaN for 2D matrices, A(:,:,:) = NaN for 3D matrices and so on.

Example:

fill_matrix_nan_output.txt
>> A = zeros(2,4)
A =

   0   0   0   0
   0   0   0   0

>> A(:,:) = NaN
A =

   NaN   NaN   NaN   NaN
   NaN   NaN   NaN   NaN

Check out similar posts by category: Octave