Sorting Problem, please help
- From: Dan <diddl11@xxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 11:17:03 -0400
I'm very new to Matlab. I am working for the summer and need to write
a lot of code, so i have been mostly teaching myself. The program I
need help with is supposed to read a text file, which consists of
several lines of code with numbers and letters. It then takes a part
of the line, some letters, and sorts it. then it goes back to the
original file and sorts those lines by the numbers. That's the idea
at least. The text file has 20 lines of code, all formated the same,
with 106 characters (including spaces and the carriage return at the
end of the line). one line looks like this (althoug it is all on a
new line):
N.CYS.104.A C.HIS.103.A 0.008697410 CA.HIS.103.A
0.846407000 N.HIS.103.A 0.715733000
The code I have, so far is:
fgzmat = fopen('gzmat.txt'); %open the file
z=106;
for i=1:20
a = fscanf(fgzmat, '%4c', [1]);
b = fscanf(fgzmat, '%5s', [1]);
c = fscanf(fgzmat, '%3d', [1]);
p = fscanf(fgzmat, '%93c', [1]);
status = fseek(fgzmat, z, 'bof');
z=z+106;
%Scan the file, making sure to count the numbers as digits, then jump
to the next line, and do it again, for all 20 lines.
foutvs = fopen('Numbers.txt', 'a');
fprintf(foutvs, '%d\n', c);
fclose(foutvs);
%Print the numbers part into a new file
end
fclose(fgzmat);
fid = fopen('Numbers.txt');
X = fscanf(fid, '%3d', [20]);
[Y,I]=sort(X);
fclose(fid);
%this part sorts the numbers and creates an index. Up to this point,
the code works.
%now I don't really know what to do. I've tried to create a file that
reads the index, and reorders the original file in that order, then
prints out a new one that is ordered in the Sorted.txt
ftemp = fopen('gzmat.txt');
for i=1:20
F(i,1)=fscanf(ftemp, '%106c', [1 1])
%scan original file in a 20x1 matrix, each line on a new row
end
fclose(ftemp);
for j=1:20
G=F(j,I); %apply index to new matrix
end
G
for i=1:20
fout = fopen('Sorted.txt', 'a'); %print out new matrix
fprintf(fout, '%c', G(i));
fclose(fout);
end
open('Sorted.txt');
I know it's a bit confusing, but as I said I am new so i'm not sure
how to write it, and I've only been doing it for about a week. Any
help anyone could give would be appreciated, and please keep it
simple so i can understand!
Thanks
.
- Follow-Ups:
- Re: Sorting Problem, please help
- From: Gautam Vallabha
- Re: Sorting Problem, please help
- From: Dan
- Re: Sorting Problem, please help
- From: Michael Wild
- Re: Sorting Problem, please help
- Prev by Date: Re: ploty - but a bar
- Next by Date: Re: Matlab 7.4 OSX
- Previous by thread: how to do change point detection for a function...
- Next by thread: Re: Sorting Problem, please help
- Index(es):
Relevant Pages
|
Loading