On Wed, Jun 24, 2009 at 6:07 PM, Jonas Amhest
<address@hidden> wrote:
hi all,
i'm using octave 3.2 on windows xp.
i have a lot of files i need to load and save, but it has to be automated.
the files have headers, data, and footers. i know how to open these but i want to incorporate a loop where the file is loaded and saved to a separate file or even just have the data saved to a separate variable through each loop.
here're are two example files:
new00.txt
asdf
asdf
1385.00 5585
2446.34 95456.74
3234.35 2343456.04
4564 53456345
5797 83456
asdf
and
new01.txt
asdf
asdf
1385.00 5585
2446.34 95456.74
3234.35 2343456.04
4564 53456345
5797 83456
asdf
to open the files i'm using this code so that it skips the headers and footers and makes a matrix out of my data:
data = "">
fid = fopen('ref00.txt');
line_string = fgetl(fid); # reads one line of the file into a string
while (line_string != -1) # makes sure its not eof
[line_data, count] = sscanf(line_string, '%f %f'); # tries to parse string; f=decimal notation
if (count == 2) # if its successful (finds 2 integers)
data = "" # append it to your data variable
end
line_string = fgetl(fid);
end
fclose(fid);
my matrix is saved into the variable data. i was trying to put the code above into a for loop that saves new00.txt into 'data00' and new01.txt into 'data01'
based off of this code:
files=dir('*.txt');
for i=1:length(files)
eval(['load ' files(i).name ' -ascii']);
end
my attempt at this was:
for i=1:length(files)
fid = fopen(files);
line_string = fgetl(fid); # reads one line of the file into a string
while (line_string != -1) # makes sure its not eof
[line_data, count] = sscanf(line_string, '%f %f'); # tries to parse string; f=decimal notation
if (count == 2) # if its successful (finds 2 integers)
data(i) = [data;line_data']; # append it to your data variable
end
line_string = fgetl(fid);
end
fclose(fid);
end
but i keep getting an error about double_value () : :wrong type argument 'struct'
any help is greatly appreciated!
-Mike
_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave