Opening multiple text files and populating a matrix with the data
Show older comments
Hi All,
I have multiple text files from signal processing analysis. There are 3 columns of data: Time, Voltage A (transmitter), Voltage B (receiver). The text files are created during tests with repeated signals; that being said the time column and Voltage A (transmitter) column are identical.
I would like to open these N text files and read the 3rd column of data; populate a matrix with the data; and then average the data to remove background noise. I believe I have correctly implemented the opening and reading of the text files, I am unsure on how to populate a matrix for averaging the signals outside the loop. The trial code I have been working on calls on 20 separate text files. So far I have:
path='C:\data\';
textFiles=dir([path '*.txt']);
for k = 1:length(textFiles)
textFilename = ['20110526-0001_' num2str(k) '.txt'];
%Open text file, 'rt' is for reading a text file only
fopen(textFilename, 'rt');
%Read file into 3 seperate variables
[Time, Transmitter, Receiver] = textscan(fid,'%d%d%d','Headerlines',3);
%Populate a cell array with data
data1=Time{i};
data2=Transmitter{i};
data3=Receiver{i};
%Close the text file
fclose(fid);
end
I prefer to have one output matrix of 22 columns: Time, Receiver A, Receiver B(1:20) after which I would take an average of Receiver B data at each timestep. As you can see above, I am getting somewhat lost trying to populate a matrix inside the loop.
Any help is appreciated. Nick
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!