|
"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,:)))
|