1

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?

Rashid
  • 4,326
  • 2
  • 29
  • 54
  • 1
    You should take a look at [this question](http://stackoverflow.com/questions/14183385/whats-the-difference-between-and-in-matlab) regarding _the difference between `|` and `||`_. (tl;dr: | can operate on arrays but || can only operate on scalars). On a side note: in order to combat the index change after `A(m > 2 , :) = [];`, you can just run `m = mean(A');` again to recalculate the indices. – Dev-iL Oct 19 '14 at 11:38
  • @Dev-iL, Good point about using the `mean` again. – Rashid Oct 19 '14 at 15:04

2 Answers2

1

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');
chappjc
  • 30,359
  • 6
  • 75
  • 132
0

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.

Rashid
  • 4,326
  • 2
  • 29
  • 54