Removing values of an array greater then threshold value
51 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gova ReDDy
am 11 Jan. 2014
Kommentiert: Benjamin Lender
am 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 Kommentare
Walter Roberson
am 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?
Akzeptierte Antwort
Walter Roberson
am 11 Jan. 2014
newmatrix = max(oldmatrix, 0);
The above would replace all negative values with 0.
newmatrix = oldmatrix;
newmatrix(oldmatrix < threshold) = 0;
1 Kommentar
Benjamin Lender
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!