basic code for automatic selection
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
John D'Errico
am 23 Mär. 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 Kommentare
Image Analyst
am 24 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!