简体   繁体   中英

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?

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');

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM