Question about extracting rows from a table based on string

Hello everyone
I wanted to store all winter ("Win") values of the rrr24 column in my data set in a new array
So I tried to do it like:
C_Winter = temp(strcmp((temp.seasons,'Win'),rrr24));
But this error appears,
C_Winter = temp(strcmp((temp.seasons,'Win'),rrr24));
Error: Invalid expression. When calling a function or indexing a variable,
use parentheses. Otherwise, check for mismatched delimiters.
I tried some other ways but all of them leads to error. Do you know what should I do?
Thank you.

댓글 수: 5

"Do you know what should I do?"
Match the parentheses:
temp(strcmp((temp.seasons,'Win'),rrr24))
% 0 12 2 10
Why are you including the column rrr24 index inside of the strcmp function call?
I don't see anything like that shown in the strcmp documentation or the table indexing documentation:
BN
BN 2020년 8월 7일
편집: BN 2020년 8월 7일
Thank you, I deleted extra columns and change it to:
t = strcmp(temp.season,'Win');
now it resulted a logical vector, i tried to use it as index:
temp (t)
But error:
Subscripting into a table using one subscript (as in t(i)) or three or more
subscripts (as in t(i,j,k)) is not supported. Always specify a row
subscript and a variable subscript, as in t(rows,vars).
Stop me.
Do you know how can I do? Thanks
Thank you I just found it:
t = temp(strcmp(temp.season,'Win'),:);
dpb
dpb 2020년 8월 7일
편집: dpb 2020년 8월 9일
The above is all columns, you said you wanted the one variable...alternatively, remove the string from the 'seasons' variable...
temp.seasons=categorical(temp.seasons); % convert to categorical variable type
C_Winter=temp.rrr24(temp.seasons=='Win'); % pick winter seasons from rrr24 array
Thank you

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

BN
2020년 8월 7일

편집:

dpb
2020년 8월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by