<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cell on
A Scripter's Notes</title><link>https://scripter.co/categories/cell/</link><description>Recent content in cell
on A Scripter's Notes</description><language>en-us</language><managingEditor>kaushal.modi@gmail.com (Kaushal Modi)</managingEditor><webMaster>kaushal.modi@gmail.com (Kaushal Modi)</webMaster><lastBuildDate>Wed, 22 Apr 2026 08:24:58 -0400</lastBuildDate><generator>Hugo -- gohugo.io</generator><docs>https://validator.w3.org/feed/docs/rss2.html</docs><atom:link href="https://scripter.co/categories/cell/index.xml" rel="self" type="application/rss+xml"/><item><title>Returning a matched group in Matlab</title><link>https://scripter.co/returning-a-matched-group-in-matlab/</link><description>&lt;p>In Matlab, the groups that are defined in parentheses are saved as &lt;em>tokens&lt;/em>.&lt;/p>
&lt;p>Here is a example where I am retreiving the first matched group or token.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-matlab" data-lang="matlab">&lt;span class="line">&lt;span class="cl">&lt;span class="n">string&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s">&amp;#39;adcout1_TAG_i.txt&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">[&lt;/span>&lt;span class="n">tok&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">regexp&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">string&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s">&amp;#39;([^_]+).*[iq]\..*&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s">&amp;#39;tokens&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">datapath_point&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">char&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tok&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">});&lt;/span> &lt;span class="c">% convert cell to string&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">% returns &amp;#39;adcout1&amp;#39; (without quotes)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Note that &amp;rsquo;tokens&amp;rsquo; argument to the Matlab regexp function makes that function
return a cell of tokens. In the above example that is stored in &lt;code>tok&lt;/code> cell. In
order to use that cell element as a string, I need to first convert it to a
string using the &lt;code>char&lt;/code> function.&lt;/p></description><category domain="https://scripter.co/categories/matlab">matlab</category><category domain="https://scripter.co/categories/regex">regex</category><category domain="https://scripter.co/categories/grouping">grouping</category><category domain="https://scripter.co/categories/cell">cell</category><category domain="https://scripter.co/categories/token">token</category><guid>https://scripter.co/returning-a-matched-group-in-matlab/</guid><pubDate>Tue, 20 May 2014 15:43:44 -0400</pubDate></item></channel></rss>