Prev: Solution Manuals, Instructor Manuals, Test Banks collection 2011 #13
Next: Solution Manuals, Instructor Manuals, Test Banks collection 2011 #15
From: Hussain on 10 Jul 2010 21:44 i am new for matlab, facing the problem regarding to new line.unable to go o the next line after writing the one complete image in row. that is the code i am using fid = fopen([datapath picaddr(1,1:fl(2)-1) 'data.txt' ],'at'); fprintf(fid, '%1.3f\t\r\n', feature) fclose(fid)
From: us on 10 Jul 2010 21:58 "Hussain " <daudbrothers(a)yahoo.com> wrote in message <i1b7l7$dp4$1(a)fred.mathworks.com>... > i am new for matlab, facing the problem regarding to new line.unable to go o the next line > after writing the one complete image in row. > that is the code i am using > > fid = fopen([datapath picaddr(1,1:fl(2)-1) 'data.txt' ],'at'); > fprintf(fid, '%1.3f\t\r\n', feature) > fclose(fid) what ...exactly... is your problem... us
From: Dinesh Iyer on 11 Jul 2010 20:45 Hi Hussain, When you execute the following lines of code, fid = fopen([datapath picaddr(1,1:fl(2)-1) 'data.txt' ],'at'); fprintf(fid, '%1.3f\t\r\n', feature) The file pointer fid is at the end of the last byte written to the file which in this case is the end of the line. When you execute another FPRINTF, it will write data to a new line. So write all lines and then close the file. However, if you would like to navigate to say the 5th line of an already existing file, you can use the following code fid = fopen('myfile.dat', 'rt'); n = 1; while n < 4 % Read one line, discard content and navigate to the start of the next line fgetl(fid); end % The file pointer is at the start of the 5th line. Hope it helps. Dinesh
From: Walter Roberson on 11 Jul 2010 21:28
Dinesh Iyer wrote: > However, if you would like to navigate to say the 5th line of an already > existing file, you can use the following code > > fid = fopen('myfile.dat', 'rt'); > n = 1; > while n < 4 > % Read one line, discard content and navigate to the start of the next > line > fgetl(fid); end > % The file pointer is at the start of the 5th line. Minor correction: add n = n + 1; somewhere between the while and 'end' statement. Alternately, for n = 1 : 4 fgetl(fid); end |