ismember input - strings vs numbers
Show older comments
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
Answers (3)
Honglei Chen
on 6 Sep 2011
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)
Matthieu
on 6 Sep 2011
Honglei Chen
on 6 Sep 2011
0 votes
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
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!