How to remove particular value from matrix?

I have 2*104 matrices ,I'm interested to remove all values below a particular value say 2.5E-4 from row 2?

9 件のコメント

Adam
Adam 2019 年 8 月 6 日
What do you want to end up with? Do you still want your matrix structure? If so you have to replace the values with something, e.g. NaN. You can't simply remove values entirely from a matrix and still have a matrix. If you do this your values will just be collapsed into a vector.
e.g.
myMatrix( 2, myMatrix( 2,: ) < 2.5e-4 ) = NaN;
would replace the values with NaN
Ramesh Bala
Ramesh Bala 2019 年 8 月 6 日
load ('testmat.mat')
peaks(2,:)
Remove=find(peaks(2,:)<=2.5e-4);
peaks(Remove)=[];
I tried ssomething liek this ,but it didnt worked
Ramesh Bala
Ramesh Bala 2019 年 8 月 6 日
Hi Adam
thanks
I just want to remove a value or two that's below the specific and still have the matrix
Adam
Adam 2019 年 8 月 6 日
So my suggested code should do this and put NaNs in there. You can put any value you want in instead of NaN, but it has to be some value and cannot be [].
Ramesh Bala
Ramesh Bala 2019 年 8 月 6 日
You mean like this
peaks( 2, peaks (2,:) < 2.5e-4 ) = 0;
but this removes my first peaks(2,1) ,I actually want to remove peaks(2,2) and make it as 0 also remove peaks(1,2) corresponding to it ,to make a equal matrix
Adam
Adam 2019 年 8 月 6 日
It helps if you can state what you want as clearly as possible in your question.
If you want to remove the whole column where row 2 meets that condition then:
peaks( :, peaks(2,:) < 2.5e-4 ) = [];
should do this.
As far as I can see only the 1st column has a value in the 2nd row that is less than your threshold.
So if you want to remove peaks(2,2) then I don't know what your condition is for doing this, but it isn't the one you originally stated. You can use <= and, in this case, that would also remove peaks(2,2), but comparing floating point values with equality is not a robust method. You would be better with something like
peaks( :, peaks(2,:) < 2.5e-4 + tol ) = [];
where you have defined tol as some small tolerance above 2.5e-4 that you want to include as effectively being equal to 2.5e-4.
Ramesh Bala
Ramesh Bala 2019 年 8 月 6 日
Alright let me give a try:) My question is to remove all value s below 2.5e-4 from row 2.
Adam
Adam 2019 年 8 月 6 日
But peaks(2,2) is not below 2.5e-4.
Ramesh Bala
Ramesh Bala 2019 年 8 月 6 日
yeah you are right :)
I tried like this with a tol and it worked well.
I will try to us it for findpeaks function later on to eliminate poor maximas.
Thanks again.

サインインしてコメントする。

回答 (0 件)

製品

タグ

質問済み:

2019 年 8 月 6 日

コメント済み:

2019 年 8 月 6 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by