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:
Removing Columns containing NaN and corresponding column in other matrix

Subject: Removing Columns containing NaN and corresponding column in other matrix

From: Hans Marx

Date: 29 Jul, 2014 20:24:11

Message: 1 of 2

Hello i have following problem

matrix A containing numbers and NaNs
same size matrix B containing only numbers

I want to:

-delete all columns containing at least one NaN in matrix A
-delete the corresponding column in matrix B
- have modified matrices C and D

No idea how to do that :( For deleting the columns with NaN i used
C = A(:,isfinite(sum(estPer3)))

However i have no idea how to delte corresponding column in B (to make D)

Thanks

Subject: Removing Columns containing NaN and corresponding column in other

From: dpb

Date: 29 Jul, 2014 21:08:06

Message: 2 of 2

On 07/29/2014 3:24 PM, Hans Marx wrote:
> Hello i have following problem
>
> matrix A containing numbers and NaNs
> same size matrix B containing only numbers
>
> I want to:
>
> -delete all columns containing at least one NaN in matrix A -delete the
> corresponding column in matrix B
> - have modified matrices C and D
...

ix=all(isfinite(A); % logical array of columns w/o any nan's
C=A(ix,:);
D=B(ix,:);

You can, of course, delete in place if don't need original A and B. In
that case any(isnan(A)) could be helpful.

See

   doc all % and friends for how/why this works

--

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