How to import column "x" from multiple excel workbooks and create a new excel file with imported columns?

I am extremely new to MATLAB and with no prior programming experience. I have a fairly large dataset, stored in excel(*.xlsx) format(2 sheets in each workbook, each sheet size with approx 660000 x 30 cells).
I need to generate spreadsheet for individual variables which are stored in same column in multiple excel workbooks (e.g. variable lat would be in column2 in all workbooks. The script that I am using is working only for 10 spreadsheets and after 10 spreadsheet I am getting 0 values.
|%This script is used in extracting single excel column from multiple files
%and writing them in another excel file
%%Load Data
dirs=dir('D:\NEE\*.xlsx');%read all the *.xlsx in the directory
%%Manipulate filenames
dircell=struct2cell(dirs); %Change the filename to strcture
filenames=dircell(1,:);
%%Read data up-to Row 17519
num = (numel(filenames)); %
Newfile = zeros(17519,num); % Allocating memory
%%Iteration
for i = 1:num
Newfile(:,i) = xlsread(filenames{i}, 1, 'L2:L17520'); % create array
end
%%create a new excel file
xlswrite('LAT07.xls',Newfile); %|
Please tell me what I am doing wrong. Your help is greatly appreciated.

3 Comments

Looks good to me. As an experiment, if you change the call to xlsread to read from filenames{1} (first file) rather than filesnames{i}, does that result in same column of data 120 times, or does that also turn to all zero columns after the tenth?
Replacing "i" with 1 results column one 120 times.
What happens if instead of running the loop from 1:N you start at 11:N?

Sign in to comment.

Answers (0)

Asked:

on 18 Jul 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!