From: us on
"jeremy meduna" <jeremymeduna(a)msn.com> wrote in message <hob53g$oo2$1(a)fred.mathworks.com>...
> A text file named "grades.txt" contains students names and grades in the following format:
> John Doe
> A A B B C
> Jane Doe
> C D C B A A
> Jill Doe
> C D F F
>
> Write a matlab script that reads the file, calculates the GPA for each student and save the fist name, last name and GPA to an excel file "gpa.xls"
>
> So far all I can come up with is:
>
> fh = fopen('grades.txt', 'r');
> line = '';
> while ischar(line)
> [first line] = fgetl(fh)
>
> Completely unsure on how to do this. Having lots of trouble in this class, would appreciate any help!

one of the many solutions

fnam='foo.txt'; % <- your file name...
s=textread(fnam,'%s','delimiter','\n');
r=cellfun(@(x) mean(sscanf(x,'%d')),s,'uni',false);
ix=cellfun(@isnan,r);
r(ix)=s(ix);
r=reshape(r.',2,[]).';
disp(r);
%{
'John Doe' [ 1]
'Jane Doe' [2.4]
'Jill Doe' [2.2]
%}
% now, use XLSWRITE

us
 | 
Pages: 1
Prev: homogeneous points
Next: xlsread_mod