help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

automated text file reading and array element extraction


From: Michael Hadrien
Subject: automated text file reading and array element extraction
Date: Thu, 2 Dec 2010 16:58:49 -0800

Hello eveyone, 

I'm a beginner in Octave, running Octave 3.2.4 on Ubuntu 10.10. 
What I'm trying to do is read numerical data in sequentially named text files in two different directories, extract the second column from each file in both directories, subtract all the columns in one directory from all the columns in the other directory, then create a new directory with a set of files containing the first column (from any directory, they're constants) and the resulting columns from the subtraction. 

So Directory A has:
aaa_001.txt
aaa_002.txt
aaa_003.txt

Directory B has: 
bbb_001.txt
bbb_002.txt
bbb_003.txt

The files all look like this:
33  32
48  45
76  34
46  54

The first column never changes. 
I want to take second columns from one directory and subtract them from all the second columns in the other directory. Both directories have the same number of files. 

This is the code I currently have:

files=dir('*.txt'); #creates struct with all files
filesarray = struct2cell(files); #converts struct array to cell array
names=filesarray(1,:) #extracts first row of cell array (where all the file names) and assigns to names

for i=1:length(names)
eval(['load ' files(i).name ' -ascii'])
end


I've repeated this for both directories. Now all the files have been loaded and I can extract column 2 from each file individually using:

aaa_001(:,2)

But I want to be able to do this for all the files automatically and do the subtraction operations. 
I'm not sure what to search or how to go about this. I've thought of maybe creating two matrices with all the col 2 data from each directory on a different matrix, but I don't know how to do that. Then I'd be able to subtract the matrices. The next step would be extracting and writing each column to a new text file.

Any help I can get would be greatly appreciated!

I've attached example files (A folder with two directories, two text files per directory).

Thank you!

--Michael

Attachment: Test.zip
Description: Zip archive


reply via email to

[Prev in Thread] Current Thread [Next in Thread]