Got Questions? Get Answers.
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:
Replace fastly values in a HUGE matrix

Subject: Replace fastly values in a HUGE matrix

From: Camille Couzi

Date: 10 Aug, 2011 08:14:13

Message: 1 of 3

Hi matlabers!
I am working with a huge matrix of data (10.000*100). In this matrix there are some values, let say =999 that I want to replace by NaN.
When I usually wok with not so big matrices, I use find function:
[row,col]=find(A==999);
A(row,col)=NaN;

but ins this case, as I have A HUGE matrix it last a loooooooong time to search for values with 'find' and more time to replace one by one the values in A.

is there a faster way to do this calculation? perhaps using a mask?

Any idea will be very welcomed. Thanks in advance!!!

camille.

        

Subject: Replace fastly values in a HUGE matrix

From: Pekka Kumpulainen

Date: 10 Aug, 2011 10:48:13

Message: 2 of 3

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <j1tekl$ch5$1@newscl01ah.mathworks.com>...
> Hi matlabers!
> I am working with a huge matrix of data (10.000*100). In this matrix there are some values, let say =999 that I want to replace by NaN.
> When I usually wok with not so big matrices, I use find function:
> [row,col]=find(A==999);
> A(row,col)=NaN;
>
> but ins this case, as I have A HUGE matrix it last a loooooooong time to search for values with 'find' and more time to replace one by one the values in A.
>
> is there a faster way to do this calculation? perhaps using a mask?
>
> Any idea will be very welcomed. Thanks in advance!!!
>
> camille.

That is not so huge, unless you have a typo in the size.
Your code takes about 0.26 seconds on my laptop if there are about 10000 instances of 999 in the matrix. But your code replaces all the combinations of the index vectors, not only the 999s, which is probably what you want.
A(A==999) = nan;
takes about 0.0066 seconds with the same matrix and this will only replace the 999s.
hth

Subject: Replace fastly values in a HUGE matrix

From: Bruno Luong

Date: 10 Aug, 2011 10:58:10

Message: 3 of 3

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message
> A(row,col)=NaN;

This command does not do what you think, and the majority of CPU time is using there unnecessary.

Bruno

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