ismember input - strings vs numbers
이전 댓글 표시
Hello,
I am using "ismember" to pullout data structured as a dataset.
- I am able to do both of these commands:
ismember(data.dataTag,0:24);
ismember(data.dataTag,{'A' 'B'});
- I would like to automate this process by feeding "ismember" a blanket series of criterion and run through all my "dataTag" of my data. I however run into trouble when I do this:
ismember(data.(dataTag{n}),{{'A' 'B'} 0:24});
ismember(data.(dataTag{n}),[{'A' 'B'} 0:24]);
The error I get is "Input must be cell arrays of strings."
Can this be done? Thank you for any help.
Matthieu
답변 (3개)
Honglei Chen
2011년 9월 6일
Hi Matthieu,
Are the criterion pre-defined? If so, how about concatenating them with logical operator, e.g.,
ismember((data.(dataTag{n}),{'A' 'B'}) || ismember((data.datqaTag{n}),0:24)
Honglei Chen
2011년 9월 6일
0 개 추천
Hi Matthieu,
I think ismember(A,B) requires A and B to be the same data type. One possible solution is to use num2str to build criterion so that criterion are all strings. Then in your function, you can use isnumeric or ischar to test the data. If the data is a number, you can do num2str again before you call ismember. However, you'll have to convert it back to number for your computation. I'm not sure if it's worthy though.
BTW, I'm also confused by you code snippet. If you need to do something like sum(c), then can c be strings? I know sum will work on strings but is that what you want?
HTH
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!