필터 지우기
필터 지우기

Removing values of an array greater then threshold value

조회 수: 52 (최근 30일)
Gova ReDDy
Gova ReDDy 2014년 1월 11일
댓글: Benjamin Lender 2021년 2월 15일
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