Modifying the elements of a matrix using a condition
조회 수: 2 (최근 30일)
이전 댓글 표시
My matrix is Y=[1 2 5 0; 3 4 0 0; 7 0 3 0; 0 0 0 1]
I want to replace zeros '0' with '0.001'
How can I do it basically?
Thanks a lot!
댓글 수: 0
답변 (1개)
Guillaume
2014년 10월 7일
편집: Guillaume
2014년 10월 7일
As long as 0 is exactly 0 (and not some very small value that's close to zero):
Y(Y==0) = 0.001;
Probably better would be, if all Y>=0
Y(Y<0.001) = 0.001;
댓글 수: 2
Guillaume
2014년 10월 7일
I don't understand what you're asking now. My answer will work whatever the shape and number of dimensions of Y.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!