basic code for automatic selection
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
John D'Errico
2015 年 3 月 23 日
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 件のコメント
Image Analyst
2015 年 3 月 24 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!