Thread Subject: Deleting NaN in a matrix

Subject: Deleting NaN in a matrix

From: Ali Hussain

Date: 26 Jun, 2008 09:08:02

Message: 1 of 5

Hello,

I am stuck I have a matrix with numbers and NaN's. I want
to delete the NaN's and reshape the matrix so i can plot it
against a similar matrix which has numbers in same
position.

14.8240 15.9172 17.0103 NaN NaN
15.3632 16.4563 17.5495 NaN NaN
NaN 16.9926 18.0858 20.9280 NaN
NaN NaN NaN 22.3190 23.4121
NaN NaN NaN 22.8581 23.9513
NaN NaN NaN NaN 24.4876
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN

Thanks


Subject: Deleting NaN in a matrix

From: Daphne

Date: 26 Jun, 2008 09:33:00

Message: 2 of 5


Why don't you use find to remove the rows where there are
no numbers any more to trim the matrix, then
b=isnan(a);
a(b)=0;
to replace the remaining NaNs with zeros?
Reshaping after that is a bit more tricky.
Does your matrix always look the same?

Daphne


"Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
<g3vm9i$34o$1@fred.mathworks.com>...
> Hello,
>
> I am stuck I have a matrix with numbers and NaN's. I
want
> to delete the NaN's and reshape the matrix so i can plot
it
> against a similar matrix which has numbers in same
> position.
>
> 14.8240 15.9172 17.0103 NaN NaN
> 15.3632 16.4563 17.5495 NaN NaN
> NaN 16.9926 18.0858 20.9280 NaN
> NaN NaN NaN 22.3190 23.4121
> NaN NaN NaN 22.8581 23.9513
> NaN NaN NaN NaN 24.4876
> NaN NaN NaN NaN NaN
> NaN NaN NaN NaN NaN
> NaN NaN NaN NaN NaN
>
> Thanks
>
>

Subject: Deleting NaN in a matrix

From: Ali Hussain

Date: 26 Jun, 2008 10:05:02

Message: 3 of 5

I would like to plot the data and Matlab plots a seperate
line for each column. If I put zero's the plot lines wil
keep returning to zero. Where I would like to plot a line
through these points(with out NaN and Zero's).

Thanks


"Daphne " <daphnew_too_nospam@yahoo.com> wrote in message
<g3vnoc$1is$1@fred.mathworks.com>...
>
> Why don't you use find to remove the rows where there are
> no numbers any more to trim the matrix, then
> b=isnan(a);
> a(b)=0;
> to replace the remaining NaNs with zeros?
> Reshaping after that is a bit more tricky.
> Does your matrix always look the same?
>
> Daphne
>
>
> "Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
> <g3vm9i$34o$1@fred.mathworks.com>...
> > Hello,
> >
> > I am stuck I have a matrix with numbers and NaN's. I
> want
> > to delete the NaN's and reshape the matrix so i can
plot
> it
> > against a similar matrix which has numbers in same
> > position.
> >
> > 14.8240 15.9172 17.0103 NaN NaN
> > 15.3632 16.4563 17.5495 NaN NaN
> > NaN 16.9926 18.0858 20.9280 NaN
> > NaN NaN NaN 22.3190 23.4121
> > NaN NaN NaN 22.8581 23.9513
> > NaN NaN NaN NaN 24.4876
> > NaN NaN NaN NaN NaN
> > NaN NaN NaN NaN NaN
> > NaN NaN NaN NaN NaN
> >
> > Thanks
> >
> >
>

Subject: Deleting NaN in a matrix

From: Simon Preston

Date: 26 Jun, 2008 10:44:02

Message: 4 of 5

"Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
<g3vpke$b85$1@fred.mathworks.com>...
> I would like to plot the data and Matlab plots a seperate
> line for each column. If I put zero's the plot lines wil
> keep returning to zero. Where I would like to plot a line
> through these points(with out NaN and Zero's).

Zeros are not necessary:
A(~isnan(A))
is a vector of the non-NaN elements of A.

Best wishes, S

Subject: Deleting NaN in a matrix

From: Élodie

Date: 26 Jun, 2008 18:21:29

Message: 5 of 5

% I assume that your both matrices are: Mymatrix1 and Mymatrix2


% Find the matrix compenent, which are different from zero and from NaN:
I = find(~isnan(Mymatrix1) & Mymatrix1~=0);

% plot the matrix element versus the other matrix element
plot(Mymatrix1(I),Mymatrix2(I))


% I hope it helps ...


--
Les Éditions Élodie Roux
www.elodieroux.com


Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com