basic code for automatic selection

8 visualizaciones (últimos 30 días)
Agastya
Agastya el 23 de Mzo. de 2015
Respondida: Image Analyst el 24 de Mzo. de 2015
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

Respuestas (2)

John D'Errico
John D'Errico el 23 de Mzo. de 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.

Image Analyst
Image Analyst el 24 de Mzo. de 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.

Categorías

Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by