I have several text files with 2 columns, containing only numbers which i would like to import into a single Excel spreadsheet (Excel 2016) using matlab. Reason for using matlab (R2014a) is because i later have scripts that process the data as well as its the only progaming language i am mildly familiar with. I tried to use the following Using matlab to save a 100 text files to a one excel file but into different spread sheet? but i just couldnt understand anything as I am a newbie and this example I think is for making several excel files while I want only one. Thanks for the help! Greatly appreciated.
1
votes
can you provide a sample text file? Reason behind asking this is to know the spacing between 2 columns in text file. Also, when you read the second text file, do you want the data in a new sheet in same workbook (or) same sheet in same workbook? If same sheet in same workbook, do you want to put the data read from second text file under the data read from first text file?
- be_good_do_good
1) I would like the data to be in the same sheet and the same workbook 2) the data from 2nd text file should be next to data from 1st text file. So 1st text file data in col 1 and col 2 and 2nd data file in col 3 and col 4 and so on........ the link for an example file is at this link filedropper.com/an050me
- fatima55
1 Answers
0
votes
content = dir();
col = 1;
for i = 1:10
if content(i).isdir ~= 1
fileID = fopen('AN050ME.ASC');
data = textscan(fileID, '%s %s');
fclose(fileID);
datum(:, col) = data{1};
col = col + 1;
datum(:, col) = data{2};
col = col + 1;
clear data;
end
end
filename = 'Datum.xls';
sheet=1;
xlswrite(filename, datum, sheet, 'A1');
close all;
This is basic working algorithm, you need to further work on it to optimize it for speeed
Hints: 1. pre-declare the size of datum, based of number of files. 2. if all the files you have to read are of same extension, read only them through dir()
Good luck for fine tuning