Table Find/Replace based on condition (greater than)

조회 수: 40(최근 30일)
Morning, In a table, how can I find values greater than 1 and replace them with NaN?
I know about the ismissing family but it does not allow (I think) for a condition (greater than), only for specific number/text.
T = table([0.1;0.2],[7;0.5],'VariableNames',{'varx1','varx2'})
The entry "7" should be NaN

채택된 답변

Image Analyst
Image Analyst 2019년 11월 23일
Try this:
T = table([0.1;0.2],[7;0.5],'VariableNames',{'varx1','varx2'})
rowsToChange = T.varx1 > 1
if ~isempty(rowsToChange)
T.varx1(rowsToChange) = nan
rowsToChange = T.varx2 > 1
if ~isempty(rowsToChange)
T.varx2(rowsToChange) = nan
  댓글 수: 3
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021년 7월 7일
Dear Image Analyst,
thanks for your tip, easy and straight.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by