Finding Maximum Value of a Table/Categorical Array

조회 수: 14 (최근 30일)
Claire Hollow
Claire Hollow 2020년 6월 10일
댓글: Paresh yeole 2020년 6월 10일
Hello! I have a question I can not get past. I have a 23000x1 table (named TMAX). It is a categorical array so it is mostly numbers but where the data is missing it is filled in with 'NA'. I am simply just looking to find the maximum value in the table. I did try
max(tmax);
but I get the error
Error using max
Invalid data type. First argument must be
numeric or logical.
I am not how to get past the NA's in there. Would even be open to switching them to NaN, whatever is simplest. Thank you in advance for the help!

채택된 답변

Paresh yeole
Paresh yeole 2020년 6월 10일
편집: Paresh yeole 2020년 6월 10일
first convert categorical to numeric array :
tmax = str2double(cellstr(tmax));
tmax(tmax == 'NA') = NaN;
max(tmax)
convert the 'NA' into NaN.
max function by default ignores the NaN values
  댓글 수: 2
Claire Hollow
Claire Hollow 2020년 6월 10일
I tried doing that but got the following error:
Error using cellstr (line 49)
Conversion to cellstr from table is not
possible.
Error in c02_warmestday (line 10)
tmax = str2double(cellstr(tmax));
I'm very thrown off because there is no line 49 either.
Paresh yeole
Paresh yeole 2020년 6월 10일
pass tmax as a array (categorical array in your case)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by