basic code for automatic selection
8 views (last 30 days)
Show older comments
I am trying to write a code that automatically select a part of code. This means that the code should go through the text file, look for key words and copy these key words with the associated value into a new file.
Please help me with that code
0 Comments
Answers (2)
John D'Errico
on 23 Mar 2015
Like a certain notable supreme court justice, I may not be able to define an obscenely bad programming idea, but I know it when I see it.
There are surely better ways to do what you are doing. Of course, we can only see what you are asking to do, so knowing what you really want to do is a bit difficult.
I might suggest writing a function, that would return the arguments you need to generate, as a function of its inputs. This will require no more than a switch case statement inside.
Or you could write a simple class, using named constants.
So many ways to do what you seem to want to do, and to do so in a way that will not be pure hell to debug. Auto-generating custom code on the fly like that is just a bad idea.
0 Comments
Image Analyst
on 24 Mar 2015
What do you mean by "associated value"? And why not just do something like this
fid1 = fopen(inputFileName, 'rt');
fid2 = fopen(outputFileName, 'wt');
textLine = fgetl(fid1);
while ischar(textLine)
index = strfind(textLine, keyword);
if ~isempty(index)
fprintf(fid2, '%s', whatever..........
end
textLine = fgetl(fid1);
end
fclose(fid1)
fclose(fid2)
I'm sure you can figure out what to do to finish it.
0 Comments
See Also
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!