フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Writing content in a text file dynamically based on an input variable

1 回表示 (過去 30 日間)
Luffy
Luffy 2015 年 10 月 17 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have a text file in which you have the following statements in the middle of text file(there are other statements starting with set word).
set TC_SYS_01 0
set TC_SYS_02 0
...
set TC_SYS_38 0
Now based on an input from GUI(say 500),i have to copy all of contents of above text file only with the following lines changed to
set TC_SYS_01 0
set TC_SYS_02 0
...
set TC_SYS_500 0
----------------------------------------------- My Code:------------------------------------------------
content = fileread('run.txt');
length = regexp(content, '(?<=set TC_SYS_\d*\s+)[01]');
% the above line is just to know how many lines of set TC_..... are present;
% input is 500,
%%%%%%%%%%%%%%%%
fid = fopen('run.txt','r');
tline = fgets(fid);
if strcmp(tline,'set TC_SYS_%d',length)
index = ftell(tline);
end
for i = length:N
% fprintf(index + 1) ??
% how to write statements after this ?
end
%%%%%%%%%%%%%%%%%
fid = fopen('run1.txt','w');
fwrite(fid,??);
fclose(fid);
If possible from the original text file which has those 38 lines of "set ...",i want to copy rest of the stuff into a new txt file & iin the new txt file i write afresh N lines of "set ...."
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 10 月 17 日
Luffy - to be clear, you want to insert lines of text into the middle of your text file. Is this correct?
Luffy
Luffy 2015 年 10 月 18 日
Yes. If input is 500 then insert 500 lines, If input is 40 then insert 40 line,

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by