what am I doing wrong with ismember?

10 ビュー (過去 30 日間)
Samyukta Ramnath
Samyukta Ramnath 2013 年 7 月 6 日
コメント済み: Stephen23 2017 年 3 月 24 日
I am trying to use ismember to find out whether a member of a cell is present in another cell array of strings. In one script, I did this -
if true
% code
end
stringyo = {'yo','I','love','you'};
test_stringyo = {'yo','you','look','funny'};
ismember(stringyo,test_stringyo{1})
which works well, gives the array 1 0 0 0, and in another script,
if true
% code
end
global Tag_sequences; % This is another cell array of strings defined elsewhere
Tags = {'DD','NN','PP','PN','ADJ','ADV','VB','PNN'};
ismember(Tag_sequences,Tags{1})
But this gives an error : Error using cell/ismember>cellismemberlegacy (line 131) Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string.
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 6 日
what is Tag_sequences?
Samyukta Ramnath
Samyukta Ramnath 2013 年 7 月 6 日
It is a previously defined global cell array of strings containing the elements of Tags in a variable order and with a variable number of elements.

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

採用された回答

the cyclist
the cyclist 2013 年 7 月 6 日
編集済み: the cyclist 2013 年 7 月 6 日
I suggest you check whether Tag_sequences is really a cell array of strings [as required by ismember()]. You can do this easily:
>> iscellstr(Tag_sequences)
I am guessing that that returns false.
You can then identify exactly which cell or cells are causing the problem:
>> cellfun(@ischar,Tag_sequences)
  5 件のコメント
Zain ul Aabidin
Zain ul Aabidin 2017 年 3 月 24 日
Then how to convert Tag_sequences = {7,'b','c'} to Tag_sequences = {'7','b','c'};
Stephen23
Stephen23 2017 年 3 月 24 日
@Zain ul Aabidin:
>> C = {7,'b','c'};
>> cellfun(@num2str,C,'uni',0)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by