Find a string cell into a variable of a table

Hi everyone!
I need to find the position of a specific string cell of Table A (first row and first column) into the first column of another Table B, how can I do?
I’ve tried with
a= strcmp(A(1,1), B(1,1));
but it doesn’t work.
The variable a is returned as 0 and it should be 1 since I know that the string cell is common between the 2 tables.
Thank you,
Anna

3 件のコメント

Mario Malic
Mario Malic 2021 年 2 月 4 日
If you run this in your code, what are the outputs?
A(1,1)
B(1,1)
KSSV
KSSV 2021 年 2 月 4 日
Have a look on contains.
Anna Mascaretti
Anna Mascaretti 2021 年 2 月 4 日
I'm sorry, there's a mistake in my question, what I've tried is
a= strcmp(A(1,1), B(:,1));
to compare the string cell A(1,1) and the first column of Tabble B (B(:,1));

サインインしてコメントする。

 採用された回答

Adam Danz
Adam Danz 2021 年 2 月 4 日
編集済み: Adam Danz 2021 年 2 月 5 日

1 投票

A(1,1) and B(:,1) return tables but strcmp is designed to accept character vector | character array | cell array of character vectors | string array.
To access the cell-strings, you need to use curly brackets!
A = table({'a'});
B = table({'a';'n';'n';'a'});
strcmp(A{1,1}, B{:,1})
ans = 4x1 logical array
1 0 0 1

その他の回答 (1 件)

KSSV
KSSV 2021 年 2 月 4 日

1 投票

Read about ismember.
idx = ismember(B(:,1),A(1,1)) ; % this will give indices where the elements match
Also have a look on contains.

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by