raulinhoo
29 May 2008, 07:59pm
Hello!
Im a new Matlab user and would like to appeal to anyone who might be able to help me with what im sure is a fairly simple problem.
I need to read a file (a python script file) into Matlab and then rewrite all the contents of this file to a new file (new python script file) with the exception of one line which will have to be changed with a new variable which will be generated in Matlab. I have written the code below so far but it doesn't do what I want.
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"> <tbody><tr> <td>Code:</td> </tr> <tr> <td class="code">fid = fopen('abaqus_gear_file56.py','r+');
fid2 = fopen('abaqus_gear_file_final.py','r+');
EEE=2.5;
for ii=1:37
data_line=fgetl(fid)
fprintf(fid2,data_line,'\n')
end
loc = 3;
for i = 1:loc
temp_line = fgetl(fid);
end;
fprintf(fid,'\n');
fseek(fid,0,'cof');
fprintf(fid,'%g',EEE);
fprintf(fid,'\n');
fclose(fid); </td> </tr> </tbody></table>
this gives me the new file with all the lines read from the old file written onto one single line, except for the new line which is written onto a separate line. I hope I have explained my problem clearly, if it is not so, please do not hesitate to ask me. Thanks for all your help in advance! hope to hear back from you all soon. THANKS!!
Best regards,
Raul "stressed matlab user!" http://www.kluid.com/mlib/images/smiles/icon_redface.gif
Im a new Matlab user and would like to appeal to anyone who might be able to help me with what im sure is a fairly simple problem.
I need to read a file (a python script file) into Matlab and then rewrite all the contents of this file to a new file (new python script file) with the exception of one line which will have to be changed with a new variable which will be generated in Matlab. I have written the code below so far but it doesn't do what I want.
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"> <tbody><tr> <td>Code:</td> </tr> <tr> <td class="code">fid = fopen('abaqus_gear_file56.py','r+');
fid2 = fopen('abaqus_gear_file_final.py','r+');
EEE=2.5;
for ii=1:37
data_line=fgetl(fid)
fprintf(fid2,data_line,'\n')
end
loc = 3;
for i = 1:loc
temp_line = fgetl(fid);
end;
fprintf(fid,'\n');
fseek(fid,0,'cof');
fprintf(fid,'%g',EEE);
fprintf(fid,'\n');
fclose(fid); </td> </tr> </tbody></table>
this gives me the new file with all the lines read from the old file written onto one single line, except for the new line which is written onto a separate line. I hope I have explained my problem clearly, if it is not so, please do not hesitate to ask me. Thanks for all your help in advance! hope to hear back from you all soon. THANKS!!
Best regards,
Raul "stressed matlab user!" http://www.kluid.com/mlib/images/smiles/icon_redface.gif