Importing large excel with different data types

12 views (last 30 days)
Dear MatLab Users Community,
I would like to import 255 .xlsx files to the Matlab. Each file contains 3500 columns; the number of rows varies. The data types of columns also vary: date-floating-text-floating 895 times further columns. The example of the data is:
02P GY Equity 0RY GY Equity 0TS GY Equity
8/4/2011 3600 NoValue 3600 3/16/2016 9271 NoValue 9271 3/22/2016 2376 NoValue 2376
8/8/2011 2125 NoValue 2125 4/1/2016 1188 NoValue 1188 3/24/2016 388.35 NoValue 388.35
8/17/2011 8369 NoValue 8369 4/6/2016 9932.4 NoValue 9932.4 3/31/2016 203.3 NoValue 203.3
8/18/2011 5097.5 NoValue 5097.5 4/8/2016 34888.75 NoValue 3488.75 4/7/2016 3954 NoValue 3954
8/22/2011 1992.6 NoValue 1992.6 4/19/2016 1563.5 NoValue 1563.5 4/8/2016 400 NoValue 400
8/23/2011 975 NoValue 975 4/28/2016 50.54 NoValue 50.54 4/14/2016 665.36 NoValue 665.36
8/24/2011 481270 NoValue 481270 4/18/2016 4101.63 NoValue 4101.63
8/26/2011 486 NoValue 486 4/19/2016 874.8 NoValue 874.8
8/29/2011 18313.9 NoValue 18313.45 4/21/2016 1510.42 NoValue 1510.42
How can I import 255 xls files of this type so that to have ONE matrix per each file?
I've tried using this code below, but it imported me "data" and "text data" matrices: Is there a way to import the files so that they look in MatLab similar to Excel?
d = dir('*.xlsx');
nfiles = size(d,1);
data = cell(1, nfiles); %preallocation for data line
for k = 1:nfiles;
disp (k)
data{k} = importdata(d(k).name);
end
clear nfiles
Thanks a lot!

Answers (1)

KL
KL on 15 Sep 2017
  5 Comments
Ekaterina Serikova
Ekaterina Serikova on 16 Sep 2017
Dear Image Analyst, if I need to import several xlsx files in a loop so that for each file a separate matrix is created, how can I do this?
Image Analyst
Image Analyst on 16 Sep 2017
Make a cell array to hold them all, but I seriously doubt you need to do this. Why can't you just use raw within the loop? Why do you need to save ALL raw cell arrays?
% Get worksheet for just this file:
[~, ~, thisRaw] = xlsread(.....
% thisRaw is a cell array from just this one particular file.
% Save this one into one cell of our cell array that holds all the raw cell arrays.
allRaw{k} = thisRaw;
Now allRaw is a cell array were each cell of that cell array contains another cell array. You like to complicate your life, don't you. Please read the FAQ so you have a chance of understanding this: FAQ entry on cell arrays

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!