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일

4 개 추천

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

I checked with whos, and the entire thing with Tag_sequences is that I have defined it to be a cell array of strings. It has the elements of tags, but in a variable order and with variable elements. whos Tag_sequences Name Size Bytes Class Attributes
Tag_sequences 1x4 248 cell global
Samyukta Ramnath
Samyukta Ramnath 2013년 7월 6일
Thank you! I got the problem. Tag_sequences gets updated whenever I run the function and the function to update it had an error halfway through, so the cell array was not fully updated. Hence it gave an error. Thank you!
the cyclist
the cyclist 2013년 7월 6일
편집: the cyclist 2013년 7월 6일
From the whos() command, I see that Tag_sequences is a cell array, but that does not mean it is a cell array of strings. Did you try the commands I suggested?
For example, it would be OK if
Tag_sequences = {'a','b','c'};
but it would not be OK if
Tag_sequences = {7,'b','c'};
Zain ul Aabidin
Zain ul Aabidin 2017년 3월 24일
Then how to convert Tag_sequences = {7,'b','c'} to Tag_sequences = {'7','b','c'};
@Zain ul Aabidin:
>> C = {7,'b','c'};
>> cellfun(@num2str,C,'uni',0)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2013년 7월 6일

댓글:

2017년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by