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

1 回表示 (過去 30 日間)
Beyhan Vurgun
Beyhan Vurgun 2021 年 1 月 11 日
回答済み: Mathieu NOE 2021 年 1 月 11 日
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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by