Thread Subject: Matrix selection

Subject: Matrix selection

From: Jose M.

Date: 24 Sep, 2009 07:57:02

Message: 1 of 3

Hi, in my program I delete some columns of a matrix which do not fulfill some conditions. However, I need to keep them. I do not want to make a new matrix, because those indexes have to be use in many other matrixes.
if I delete the columns these way A(:,del)=[]; however, what I want to do to see what I am removing and what not, so I would need something like "select the values of A which are not del". Does anyone know how to do this in a simple way?

Subject: Matrix selection

From: Sebastiaan

Date: 24 Sep, 2009 10:11:03

Message: 2 of 3

"Jose M. " <perezmac@student.chalmers.se> wrote in message <h9f8oe$rjg$1@fred.mathworks.com>...
> Hi, in my program I delete some columns of a matrix which do not fulfill some conditions. However, I need to keep them. I do not want to make a new matrix, because those indexes have to be use in many other matrixes.
> if I delete the columns these way A(:,del)=[]; however, what I want to do to see what I am removing and what not, so I would need something like "select the values of A which are not del". Does anyone know how to do this in a simple way?

You can use 2 approaches.

The correct solution is to use an idexing vector:
A = rand(10,10);
ActiveColumns = 1:size(A,2);
% Delete column 'del'
ActiveColumns = setdiff(ActiveColumns, del);
% Show A
A(:, ActiveColums)

If the cheap solution works depends on what you are doing. You can for example substitute NaNs, or Infs or any other value which is not valid for your dataset (e.g. if all elements should be >=0, the value -1 can be used to indicate a deleted column):
A = rand(10,10);
A(:, del) = NaN;
A(:, ~isnan(A(1,:)))

Subject: Matrix selection

From: Jose M.

Date: 24 Sep, 2009 15:07:03

Message: 3 of 3

Thank you, it was very precise and exactly what I wanted. The first solution I mean.

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
matrix Jose M. 24 Sep, 2009 03:59:06
submatrices Jose M. 24 Sep, 2009 03:59:06
rssFeed for this Thread

Contact us at files@mathworks.com