How can I insert NaN value in a matrix?
조회 수: 15 (최근 30일)
이전 댓글 표시
Suppose I have this matrix
a = [1:6; 7:12; 13:18; 19:24]
I want to fill the values for all the even number with NaN. How can I do it? For example, the first row of my matrix should look like:
a(1,:) = 1 NaN 3 NaN 5 NaN
댓글 수: 0
채택된 답변
dpb
2021년 11월 30일
편집: dpb
2021년 11월 30일
a(iseven(a))=nan; % iseven() is in Signal Processing TB
w/o the SP TB, it's not much more
a(~mod(a,2))=nan;
These are logical addressing/indexing expressions, one of the most powerful of all MATLAB syntax features. Look for and read section in the documentation on addressing matrices to learn more.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!