Azzera filtri
Azzera filtri

Removing values of an array greater then threshold value

52 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 11 Gen 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?
Gova ReDDy
Gova ReDDy il 11 Gen 2014
Just one to replace the values lower than the threshold with 0

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 11 Gen 2014
newmatrix = max(oldmatrix, 0);
The above would replace all negative values with 0.
newmatrix = oldmatrix;
newmatrix(oldmatrix < threshold) = 0;
  1 Commento
Benjamin Lender
Benjamin Lender il 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

Accedi per commentare.

Più risposte (0)

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by