How to check for strings in a cell array using ismember.

7 ビュー (過去 30 日間)
Santiago Chazaro
Santiago Chazaro 2023 年 6 月 12 日
編集済み: Santiago Chazaro 2023 年 6 月 12 日
Hi, I have a cell array as follows:
B =
8x1 cell
17x1 cell
11x1 cell
12x1 cell;
Where each cell containts an array of strings e.g. B{1,1} = ['b12', 'b44', a17']
I would like to check the entire cell array B for specific strings, such as 'b12', and output the index.
I tried using ismember
ismember(A{i}(j,1), B), where A is the specific string
but the following error code is shown:
Input A of class cell and input B of class cell must be cell arrays of character vectors, unless one is a character vector.
I have also tried the following: any(strcmp(B,A{i}(j,1))) to no avail as this shows the same result for all strings of A, even if they dont exist in B.
Edit: A little more context, A is also a cell array, where i references the cell in the cell array, and j refereneces the specific entry in that cell. I would like to search for each specific entry, i.e. j, in every cell of B.

採用された回答

VBBV
VBBV 2023 年 6 月 12 日
編集済み: VBBV 2023 年 6 月 12 日
ismember(A{i}(j,1), B{i})
  2 件のコメント
VBBV
VBBV 2023 年 6 月 12 日

Try using the cell array index for B

Santiago Chazaro
Santiago Chazaro 2023 年 6 月 12 日
編集済み: Santiago Chazaro 2023 年 6 月 12 日
Should I just use a for loop to check every cell in B ?
Edit: Yes

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by