<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.101.0">Hugo</generator><title type="html">cell on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/categories/cell/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/categories/cell/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/categories/cell/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/categories/cell/jf2feed.json" rel="alternate" type="application/jf2feed+json" title="jf2feed"/><updated>2026-04-22T08:24:57-04:00</updated><author><name>Kaushal Modi</name><email>kaushal.modi@gmail.com</email></author><id>https://scripter.co/categories/cell/</id><entry><title type="html">Returning a matched group in Matlab</title><link href="https://scripter.co/returning-a-matched-group-in-matlab/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/returning-a-matched-group-in-matlab/</id><published>2014-05-20T15:43:44-04:00</published><updated>2014-05-20T15:43:44-04:00</updated><content type="html"><![CDATA[<p>In Matlab, the groups that are defined in parentheses are saved as <em>tokens</em>.</p>
<p>Here is a example where I am retreiving the first matched group or token.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-matlab" data-lang="matlab"><span class="line"><span class="cl"><span class="n">string</span> <span class="p">=</span> <span class="s">&#39;adcout1_TAG_i.txt&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="n">tok</span><span class="p">]</span> <span class="p">=</span> <span class="n">regexp</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="s">&#39;([^_]+).*[iq]\..*&#39;</span><span class="p">,</span> <span class="s">&#39;tokens&#39;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">datapath_point</span> <span class="p">=</span> <span class="n">char</span><span class="p">(</span><span class="n">tok</span><span class="p">{</span><span class="mi">1</span><span class="p">});</span> <span class="c">% convert cell to string</span>
</span></span><span class="line"><span class="cl"><span class="c">% returns &#39;adcout1&#39; (without quotes)</span>
</span></span></code></pre></div><p>Note that &rsquo;tokens&rsquo; argument to the Matlab regexp function makes that function
return a cell of tokens. In the above example that is stored in <code>tok</code> cell. In
order to use that cell element as a string, I need to first convert it to a
string using the <code>char</code> function.</p>]]></content><category scheme="https://scripter.co/categories/matlab" term="matlab" label="matlab"/><category scheme="https://scripter.co/categories/regex" term="regex" label="regex"/><category scheme="https://scripter.co/categories/grouping" term="grouping" label="grouping"/><category scheme="https://scripter.co/categories/cell" term="cell" label="cell"/><category scheme="https://scripter.co/categories/token" term="token" label="token"/></entry></feed>