Table Find/Replace based on condition (greater than)

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
end
rowsToChange = T.varx2 > 1
if ~isempty(rowsToChange)
T.varx2(rowsToChange) = nan
end

댓글 수: 3

Dave
Dave 2019년 11월 23일
Thanks, I take that there is no vectorized way to deal w conditionals for tables?
Image Analyst
Image Analyst 2019년 11월 23일
편집: Image Analyst 2021년 7월 8일
What are "w conditionals"?
It is vectorized by column.
The reason I did it by columns is that some columns (not in this case though) might not be numeric, in general. So you can't just convert the whole table to a numerical array, then do the whole matrix vectorized at once, then convert back to a table, unless you know what column numbers are numeric.
Dear Image Analyst,
thanks for your tip, easy and straight.
Best.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기

질문:

2019년 11월 23일

편집:

2021년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by