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
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
2019 年 8 月 6 日
Ramesh Bala
2019 年 8 月 6 日
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
2019 年 8 月 6 日
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
2019 年 8 月 6 日
Adam
2019 年 8 月 6 日
But peaks(2,2) is not below 2.5e-4.
Ramesh Bala
2019 年 8 月 6 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!