how to extract particular data from .m file
Show older comments
hello,
For example, I have code in file like below.
cs.set_param('SimCustomHeaderCode', sprintf('%s\n%s','#define A1 10','#define RESLOLUTION 0.25')); % Header file
cs.set_param('CustomHeaderCode', sprintf('%s\n%s','#define A2 10','#define RESLOLUTION_1 0.25')); % Header file
cs.set_param('CustomSourceCode', '#include "verify_includes.c"'); % Source file
I want to extract CustomHeaderCode in one array and CustomSourceCode names in other array.I tried to do using regexp like below:
str = fileread('active_configuration.m');
[macroNames Index] = regexp(str,'(?<=\#define)\s+(\w+)','match','start')
but it gives me unwanted names also.
I am expecting answer as A1,RESLOLUTION,A2 and RESLOLUTION_1 in one array and verify_includes in another array.
Accepted Answer
More Answers (0)
Categories
Find more on Variables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!