String comparison in table

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 comentario

Bhaskar R
Bhaskar R el 25 de Nov. de 2019
Editada: Bhaskar R el 25 de Nov. de 2019
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'}

Iniciar sesión para comentar.

Respuestas (1)

AKARSH KUMAR
AKARSH KUMAR el 24 de Jun. de 2020

0 votos

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

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 25 de Nov. de 2019

Respondida:

el 24 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by