How do I import a column (f.e. C2:C37) of multiple Excel files into one vector in Matlab?

2 次查看(过去 30 天)
I am currently trying to figure out a loop, but am an absolute beginner and have difficulties to find the right commands for it.
One thing that I probably need to mention is that the column is the same for each file (hence same rows etc), but some of the columns have randomly empty cells that I would like to replace with 0.
The order of that final vector is important too.
Thanks very much in advance!
  3 个评论
Beyhan Vurgun
Beyhan Vurgun 2021-1-11
Thank you. Unfortunately I could not figure out how to read then just one column out of all the excel files that I successfully imported, and with those create one column vector?
dpb
dpb 2021-1-11
Either use the 'Range' argument to limit the range (only works for spreadsheets) or just read the whole array and keep only what is needed--generally at least as fast if not faster than the special-case of reading only subset of a file.

请先登录,再进行评论。

回答(1 个)

Mathieu NOE
Mathieu NOE 2021-1-11
hello
this is a simple code to load multiple excel (one sheet) data
you can build your solution on this example
file_list = dir('*.xlsx'); % list all xlsx files in current directory
for i = 1:length(file_list)
filename = file_list(i).name;
data_in{i} = xlsread(filename,range); % stores the filename data in array of cells
% insert your code here
end

Community Treasure Hunt

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

Start Hunting!

Translated by