Creating a function that goes through a Matrix and scans for any values lesser than 0 (so -1 for example) ?

조회 수: 3 (최근 30일)
I need help with creating a function that goes through a Matrix and scans for any values lesser than 0 (so -1 for example) and then replaces it with a 0 if it is less than 0 but does not change any other value that is equal to zero or greater than zero and finally returns back the original input matrix with the less than 0 numbers converted to zero.

채택된 답변

ME
ME 2019년 11월 5일
편집: ME 2019년 11월 5일
For a matrix A
A(A<0)=0
will convert all negative values to zeros.
  댓글 수: 2
BBB
BBB 2019년 11월 5일
Just wondering how would you use this line of code to create a flexible user-defined function for any arbitrary matrix input made up of negative, 0 and positive numbers?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by