Prev: Save text and numeric data into one text file
Next: Problem with prtools - PR_Warning: getprior: No priors found in dataset, class frequencies are used instead
From: Jan Simon on 19 Jan 2010 14:20 Dear Hadassa! > I have a large file of about 2000 rows and many more columns. Do you want to sort each row, all rows together or the sequence of rows? > I want to sort the rows in this file according to a new index I have created. Is this index a part of the rows or do you have it separately? > That is, I actually do not care about the format of the values or the values > when I read in the file. I would just like to read it in, sort it and write it back > into the same file. So what you need is a tool to read a file to a cell string with each line in a cell? This would be: C = dataread('file', FileName, '%s', 'delimiter', '\n', 'whitespace', ''); Then write the cell in sorted order: FID = fopen(FileName, 'wt'); fprintf(FID, '%s\n', C{SortIndex}); fclose(FID); If speed is critical and the file is really large, you coud try to use this: FID = fopen(FileName, 'wt'); fwrite(FID, cat(1, C{SortIndex}), 'uchar'); fclose(FID); or try if CStr2String is faster: fwrite(FID, CStr2String(C(SortIndex)), 'uchar'); http://www.mathworks.com/matlabcentral/fileexchange/26077 Good luck, Jan |