Removing values of an array greater then threshold value
51 views (last 30 days)
Show older comments
Gova ReDDy
on 11 Jan 2014
Commented: Benjamin Lender
on 15 Feb 2021
Hello,
I have an array of size 500x1 and I want to make the values lesser than threshold value to zero while copying the same values of array which are less than the threshold. can I know how to do this.
thanks.
2 Comments
Walter Roberson
on 11 Jan 2014
Huh? You want as output two arrays, one with the numbers that were less than the threshold, and the other being the original except with those lower numbers set to 0?
Or you just want to replace the values lower than the threshold with 0?
Accepted Answer
Walter Roberson
on 11 Jan 2014
newmatrix = max(oldmatrix, 0);
The above would replace all negative values with 0.
newmatrix = oldmatrix;
newmatrix(oldmatrix < threshold) = 0;
1 Comment
Benjamin Lender
on 15 Feb 2021
Dear Mr. Roberson,
I am dealing with large matrices n x n with n > 100,000, sometimes n > 1,000,000. The matrix is a sparse matrix.
The calculation terminates with "Requested array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive."
Is there a way of doing this calculation that is more efficient in terms of required memory (or whatever storage is the bottleneck)?
I have unsuccessfully tried
A.*(A>Threshold))
as suggested by https://de.mathworks.com/matlabcentral/answers/27314-how-to-remove-elements-in-a-matrix-less-than-a-threshold
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!