Emacs, scripting and anything text oriented.

Returning a matched group in Matlab

Kaushal Modi

In Matlab, the groups that are defined in parentheses are saved as tokens.

Here is a example where I am retreiving the first matched group or token.

string = 'adcout1_TAG_i.txt';
[tok] = regexp(string, '([^_]+).*[iq]\..*', 'tokens');
datapath_point = char(tok{1}); % convert cell to string
% returns 'adcout1' (without quotes)

Note that ‘tokens’ argument to the Matlab regexp function makes that function return a cell of tokens. In the above example that is stored in tok cell. In order to use that cell element as a string, I need to first convert it to a string using the char function.

If you have written a response to this, enter your response post's URL below.

Or, you can send a "comment" webmention (it's OK if you don't know what that means). When asked about your website on an IndieAuth login screen, simply type https://commentpara.de.

Markdown Support**bold**, _italics_, ~~strikethrough~~, [descr](link), `monospace`, ```LANG\nline1\nline2\n``` (Yep, multi-line code blocks too, with syntax highlighting!), auto-hyperlinking.

Webmentions #