|
From: | Liam Groener |
Subject: | Re: file input question |
Date: | Fri, 5 Feb 2010 20:13:54 -0800 |
On Feb 5, 2010, at 4:04 PM, Tim Rueth wrote:
There are different ways of doing your file input. See the input/output section of the manual. One way is illustrated with the following script: clear fid = fopen('mydata','r'); #Assumes mydata is your file name. #You could interactively input a file name s=0; if fid == -1 disp("Couldn't find file mydata") else while ~feof(fid) #while not end-of-file [a,b,c,d,e] = fscanf(fid,'%g %g %g %g %g','C'); # Do some stuff with the variables, .e.g: s = s+a+b+c+d+e; end end fclose(fid) #Output something: s It is the 'C' in the fscanf call that makes it input one line at a time. In this case, It actually would be more efficient to read the whole file at once into a matrix: [v,count]=fscanf(fid,'%g %g %g %g %g',[1,inf]); s = sum(v) As for your second question, setting PS1 in my .octaverc file works for me, Octave-3.2.3. Are you using the development version? |
[Prev in Thread] | Current Thread | [Next in Thread] |