フィルターのクリア

How do I import many excel files in MATLAB?

1 回表示 (過去 30 日間)
JIN-HWA JEONG
JIN-HWA JEONG 2016 年 4 月 29 日
コメント済み: John BG 2016 年 4 月 29 日
I use a code, like this. But Just 1 of 5 file is imported. I want to import 5 files.
source_dir = 'C:/Users/Cju/Documents/MATLAB/a/' ;
dest_dir = '/C:/Users/Cju/Documents/MATLAB/a' ;
source_files = dir(fullfile(source_dir, '*.xlsx'));
for i = 1:length(source_files)
data = xlsread(fullfile(source_dir, source_files(i).name));
xlswrite(fullfile(dest_dir, source_files(i).name));
end
  2 件のコメント
louis rassinfosse
louis rassinfosse 2016 年 4 月 29 日
編集済み: louis rassinfosse 2016 年 4 月 29 日
I suppose only your last file is imported? That is because the name data, is the same for all 5 files..
Try:
-----------------------
For i=...
Data(i) =...
End
----------------------
(Not sure if it is '(i)' or {i}' but one should work )
John BG
John BG 2016 年 4 月 29 日
With your for loop writing the output of xlsread in exactly the same variable called 'data' you will not be able to read any other spreadsheet than the last one.
First build different variables, or a matrix the size you want to hold the data, fill it up with zeros if dealing with numeric, or build a basic cell that you can concatenate in the same for loop and then read with the for loop:
data={}
for k=1:N_files
[d1 d2 d3]=xlsread(...)
data=[data ; d3]
end
check your syntax of xlsread and xlswrite, the:
  • variables
  • worksheet page
  • cell ranges
are missing.

サインインしてコメントする。

回答 (1 件)

louis rassinfosse
louis rassinfosse 2016 年 4 月 29 日
I suppose only your last file is imported? That is because the name data, is the same for all 5 files..
Try:
-----------------------
For i=...
Data(i) =...
End
----------------------
(Not sure if it is '(i)' or {i}' but one should work )

カテゴリ

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