MATLAB: To find variables in a string

MATLABprogrammingstringstext file

Hello,
this may be a simple problem. but i cant figure it out.
I have a string which is acquired from an .m file through fgetl function. How can i find the existence of any variable or built-in function inside that string? is there built-in function for searching variable name or built-in function name inside a string?
-obli

Best Answer

For variables use symvar(str). It will create a cell array of variable names.
Finding "built-in" functions can be performed using cellfun(@exist,cell_array_input)==5.
The 5 denotes built-in low level functions. A value of 2 is likely what you also want and these are the Toolbox functions like "filter2", "interp2" or "smooth3".
Another form to use directly on a string is of the form exist('log2','builtin').
To create the cell_array_input from a string use:
cell_array_input=regexp(str, '[a-zA-Z][a-zA-Z0-9]+','match')
This forces the first letter to be alphanumeric but allows functions like interp2 to be captured