How to assign Nans to specific column, not entire row
조회 수: 20 (최근 30일)
이전 댓글 표시
Hello!
I am trying to assign NaNs to values under 0.95, but only for the rows in column 4, not all of the columns.
Before, I used:
ZB1array = table2array(ZB1);
idx = ZB1array(:,4) < 0.95;
ZB1array(idx,: ) = NaN;
This successfully assigned NaNs, but to the entire row. In order to assign them to rows only in column 4 I tried:
ZB1array(idx, ZB1array(:,4)) = NaN;
But this returns the error 'Index in position 2 is invalid. Array indices must be positive integers or logical values.'
Does anyone know what I should do? Thanks!
댓글 수: 0
채택된 답변
Scott MacKenzie
2022년 3월 11일
편집: Scott MacKenzie
2022년 3월 11일
Your first attempt was almost correct. Here's the fix:
ZB1array = rand(5,5) % test data
idx = ZB1array(:,4) < 0.95;
ZB1array(idx,4) = NaN % must specify column 4
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!