Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
getting rid of NaN's

Subject: getting rid of NaN's

From: sujata

Date: 30 Sep, 2009 07:54:01

Message: 1 of 3

Hi

I have a 6 by 10 matrix with numbers and a couple of Nan's in it in various places.
I used the function isnan to locate this.

I want to get rid of the NaN's by replacing them with blanks which woudl still leave me with a 6 by 10 matrix where the Nans are just empty spots.

I tried converting it to strings and then replacing them with empty strings but taht doesn't work.

Does anyone know a fast way to do this.

Thanks for any help

Subject: getting rid of NaN's

From: Dave Brackett

Date: 30 Sep, 2009 09:05:19

Message: 2 of 3

"sujata " <sujatagp@gmail.com> wrote in message <h9v2qp$qal$1@fred.mathworks.com>...
> Hi
>
> I have a 6 by 10 matrix with numbers and a couple of Nan's in it in various places.
> I used the function isnan to locate this.
>
> I want to get rid of the NaN's by replacing them with blanks which woudl still leave me with a 6 by 10 matrix where the Nans are just empty spots.
>
> I tried converting it to strings and then replacing them with empty strings but taht doesn't work.
>
> Does anyone know a fast way to do this.
>
> Thanks for any help

you can't have a blank entry in a matrix because that would be NaN. You could do it if you use a cell array. help cell.

Subject: getting rid of NaN's

From: Sebastiaan

Date: 30 Sep, 2009 09:15:19

Message: 3 of 3

"sujata " <sujatagp@gmail.com> wrote in message <h9v2qp$qal$1@fred.mathworks.com>...
> Hi
>
> I have a 6 by 10 matrix with numbers and a couple of Nan's in it in various places.
> I used the function isnan to locate this.
>
> I want to get rid of the NaN's by replacing them with blanks which woudl still leave me with a 6 by 10 matrix where the Nans are just empty spots.
>
> I tried converting it to strings and then replacing them with empty strings but taht doesn't work.
>
> Does anyone know a fast way to do this.
>
> Thanks for any help
If it is just for displaying, write your own matrix displayer:
for i=1:size(A,1)
  for j=1:size(A,2)
    if ~isnan(A(i,j))
      fprintf('%10.4f ', A(i,j));
    else
      fprintf('%10s', ' '); %10 spaces
    end
  end
  fprintf('\n');
end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us