On Tuesday, October 1, 2013 8:56:06 AM UTC+13, Andreas wrote: > Hello, i have the following problem. > > > > I have a cfd. file that i can read and edit it via text editor such as notepad. What i want, is from that file to change specific numbers in it. I already used a variety of the printf, textscan and such commands but the problem is that for some reason it changes the structure of the file. > > The .cfd file is the following: > > > > http://speedy.sh/u4JSp/Demo-CFD0-hallway.cfd > > > > I want to change a number without ruin the structure of the file because then i use that file in a program. If i change the structure, the program will be unable to read it. What i mean by changing the structure, you will see by yourselves if you run the standard textscan and fprintf commands. > > > > Thanks in advance, i am out of ideas here!!!
One way of retaining the structure of your file is to read it in holus bolus, then write it out the same way: fid=fopen('myfile.txt','rt'); a=fscanf(fid,'%c'); % Now a is a long string containing everything, including CR LF tabs etc etc fclose(fid); % Make the changes in a a=strrep(a,'OldNumber','NewNumber'); etc % Write out the new version fid=fopen('myfile_new.txt','wt'); fprintf(fid,'%c',a); fclose(fid);