Removing values of an array greater then threshold value

52 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2014-1-11
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 2014-1-11
Just one to replace the values lower than the threshold with 0

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2014-1-11
newmatrix = max(oldmatrix, 0);
The above would replace all negative values with 0.
newmatrix = oldmatrix;
newmatrix(oldmatrix < threshold) = 0;
  1 个评论
Benjamin Lender
Benjamin Lender 2021-2-15
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by