What's the use of Deterministic Regular Expressions?

MATLAB: How can I use regular expressions to collect a list of variable names that satisfy a particular pattern?

  • I have a set of variables in my workspace. I want to use regular expressions regexp to get the name of the variable names that match a particular pattern.

  • Answer:

    Step 1: Get all the MATLAB variable names from the workspace using listOfVarNames = whos; . Step 2: Iterate over all variable and check if they match the pattern of your interest: for idx = 1:numel(listOfVarNames); regexp(listOfVarNames,'pattern'); end The code above will print if the variable name matched the pattern or not.

Lokesh Amarnath at Quora Visit the source

Was this solution helpful to you?

Other answers

Building on another answer: % Gets variables from current workspace. listOfVarNames = whos; % Use strfind to do the regexp stringsWhichMatch = strfind( {listOfVarNames.name}, 'pattern' ); % Use find to get the indices of interest indicesOfVariables = find( [ stringsWhichMatch{:} ] ); % Dump variables names into a cell array variablesOfInterest = { listOfVarNames( indicesOfVariables ).name} The documentation is your friend: http://www.mathworks.com/support/ Look for the functions that you need more info on in the documentation.

Prabhakar Govind

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.