<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/320055</link>
    <title>MATLAB Central Newsreader - find an element in a cell data type</title>
    <description>Feed for thread: find an element in a cell data type</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.ch/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 14 May 2012 16:43:07 +0000</pubDate>
      <title>find an element in a cell data type</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/320055#876751</link>
      <author>karlo gonzales</author>
      <description>Hi ,&lt;br&gt;
&lt;br&gt;
suppose you have a cell variable type as  :   LABEL= {'AB', 'CD', 'EF',.....'YZ' } ;&lt;br&gt;
&lt;br&gt;
and you want to check if another variable( e.g., var1='CD') is one of those in LABEL, &lt;br&gt;
&lt;br&gt;
using   LABEL==var1  or find(LABEL,var1)  both gives error.    &lt;br&gt;
&lt;br&gt;
what's the correct way to check if the "var1" is one element of the LABEL?&lt;br&gt;
&lt;br&gt;
thanks</description>
    </item>
    <item>
      <pubDate>Mon, 14 May 2012 16:57:12 +0000</pubDate>
      <title>Re: find an element in a cell data type</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/320055#876753</link>
      <author>Bruno Luong</author>
      <description>"karlo gonzales" wrote in message &amp;lt;jorcmr$skc$1@newscl01ah.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi ,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; suppose you have a cell variable type as  :   LABEL= {'AB', 'CD', 'EF',.....'YZ' } ;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and you want to check if another variable( e.g., var1='CD') is one of those in LABEL, &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; using   LABEL==var1  or find(LABEL,var1)  both gives error.    &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; what's the correct way to check if the "var1" is one element of the LABEL?&lt;br&gt;
&lt;br&gt;
any(strcmp('CD', LABEL)) % return the true if var1 is found&lt;br&gt;
find(strcmp('CD', LABEL)) % return where is 'CD' in LABEL&lt;br&gt;
&lt;br&gt;
% Bruno</description>
    </item>
    <item>
      <pubDate>Mon, 14 May 2012 17:19:07 +0000</pubDate>
      <title>Re: find an element in a cell data type</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/320055#876758</link>
      <author>karlo gonzales</author>
      <description>"Bruno Luong" &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;jordh8$2v3$1@newscl01ah.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "karlo gonzales" wrote in message &amp;lt;jorcmr$skc$1@newscl01ah.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi ,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; suppose you have a cell variable type as  :   LABEL= {'AB', 'CD', 'EF',.....'YZ' } ;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; and you want to check if another variable( e.g., var1='CD') is one of those in LABEL, &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; using   LABEL==var1  or find(LABEL,var1)  both gives error.    &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; what's the correct way to check if the "var1" is one element of the LABEL?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; any(strcmp('CD', LABEL)) % return the true if var1 is found&lt;br&gt;
&amp;gt; find(strcmp('CD', LABEL)) % return where is 'CD' in LABEL&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Bruno&lt;br&gt;
&lt;br&gt;
&amp;nbsp;Exactly what i was looking for. Than you so much Bruno!.</description>
    </item>
    <item>
      <pubDate>Mon, 14 May 2012 20:53:07 +0000</pubDate>
      <title>Re: find an element in a cell data type</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/320055#876771</link>
      <author>Ben </author>
      <description>&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; any(strcmp('CD', LABEL)) % return the true if var1 is found&lt;br&gt;
&amp;gt; &amp;gt; find(strcmp('CD', LABEL)) % return where is 'CD' in LABEL&lt;br&gt;
&lt;br&gt;
I would've suggested ismember, but you're right -- any(strcmp()) works as well.  In fact, it seems much faster.  Why is ismember slower?</description>
    </item>
    <item>
      <pubDate>Mon, 14 May 2012 21:03:07 +0000</pubDate>
      <title>Re: find an element in a cell data type</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/320055#876772</link>
      <author>Bruno Luong</author>
      <description>"Ben" wrote in message &amp;lt;jorrbj$7lg$1@newscl01ah.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I would've suggested ismember, but you're right -- any(strcmp()) works as well.  In fact, it seems much faster.  Why is ismember slower?&lt;br&gt;
&lt;br&gt;
Just a guess, but there are perhaps one or two reasons:&lt;br&gt;
&lt;br&gt;
1) ismember() works on two cell arrays, the internal engine must do a sorting of the strings, thus slow.  strcmp() simply goes through the cell and compares two strings. On the complexity, algorithm used by strcmp is better when one array is a single strings.&lt;br&gt;
&lt;br&gt;
2) ismember might have more overhead.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
  </channel>
</rss>
