Rash
Rash

Reputation: 4336

Removing some indexes of a matrix in MATLAB

I have a 2D matrix, A, each row representing a sample of signal,

I want to filter it by removing the samples having mean more and less than a threshold.

so I calculate the mean like m = mean(A');

then I want to do something like

A(m > 2 || m < 1 , :) = [];

Which faces with an error,

I tried doing like,

A(m > 2 , :) = [];
A(m < 1 , :) = [];

But I realized that after executing the first line, the indexes change and ...

So what can I do?

Upvotes: 1

Views: 50

Answers (2)

chappjc
chappjc

Reputation: 30579

The comments are suggesting you use element-wise or instead of scalar.

This:

A(m > 2 | m < 1 , :) = [];

Not this:

A(m > 2 || m < 1 , :) = [];

But, as with your other question, I strongly recommend using a dimension argument to mean instead of transposing the input matrix to mean:

m = mean(A,2).'; % NOT m = mean(A');

Upvotes: 1

Rash
Rash

Reputation: 4336

I did this:

 A(m > 2,:) = NaN;
 A(m < 1,:) = NaN;
 A(any(isnan(A),2),:) = [];

I don't know if it is efficient enough, but it did the job.

Upvotes: 0

Related Questions