Import file excel with different length

17 views (last 30 days)
Fredic
Fredic on 7 May 2020
Edited: Fredic on 18 May 2020
Hi I would like to know if there is an easy way to import Excel files of different length. In particular, each Excel file is composed by 4 variables.
I should create an array that contains each vector of the files and put them by column.
In detail, I enclose my code.
clc
folder='C:\Users\....';
d=dir(folder)
e={d.name}
f=e(~cellfun(@isempty,regexp(e,'.+(?=\.xlsx)','match')))
for k=1:numel(f)
data{k,1}=xlsread(f{k})
end
This is the matrix that contains all the data that then groups them together for similar variables:
M=cell2mat(data');
The problem is that each vector of array has a different length. (give error)
The goal is then separted each variable in this way:
cc11=M(:,1:4:end);
tt11=M(:,2:4:end);
cc22=M(:,3:4:end);
tt22=M(:,4:4:end);
Thanks a lot in advance and I hope someone can give me suggestions!!!!
  10 Comments

Sign in to comment.

Answers (1)

ChrizzzlP
ChrizzzlP on 7 May 2020
You could specify a range that has the length of the longest vector (xlrange), which will load in empty cells as NaN, which you could then later remove. Or load in the 4 vectors seperately from the start (also can be done by specifying the range)
  7 Comments
Fredic
Fredic on 7 May 2020
eh no.. not work..
Brace indexing is not
supported for variables of
this type.
Error in cell2mat (line 42)
cellclass = class(c{1});
Error in Fitting_function
(line 19)
M = cell2mat(data{i,1});

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!