필터 지우기
필터 지우기

String comparison in table

조회 수: 25 (최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2019년 11월 25일
답변: AKARSH KUMAR 2020년 6월 24일
This is a follow up to my previous question.
t = table({'1', '2'; '2', '3'; '2', '3'; '4', '5'}, [1; 2; 1; 2], 'VariableNames', {'Multico', 'value'})
tochange = strcmp(t.Multico(1, :), '2')
Expected output:
tochange =
1×2 logical array
0 1 1
Obtained output:
tochange =
1×2 logical array
0 1
I'd like to know why the expected output is not obtained.
Any suggestions on how to obtain the expected output?
  댓글 수: 1
Bhaskar R
Bhaskar R 2019년 11월 25일
편집: Bhaskar R 2019년 11월 25일
You are comparing 2 values of the table variable t.Multico row 1 (total 2 elements) to string '2' thats why got only two logical outputs
>> t.Multico(1, :)
ans =
1×2 cell array
{'1'} {'2'}

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

답변 (1개)

AKARSH KUMAR
AKARSH KUMAR 2020년 6월 24일
The reason is you are not comparing a single value but multiple values in this case two values of the table.
Like in your case t.Multico row 1 (total 2 elements) to string '2' thats why got only two logical outputs

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by