複数のExcelファ​イルから指定のデータ​を呼び出す方法につい​て

24 次查看(过去 30 天)
Hiroki Takeda
Hiroki Takeda 2022-8-24
フォルダ内にExcelファイル一式があり,ファイルの中身のフォーマットは全て同じです。
「それぞれのファイルの指定のシートのC列」から「0より大きく5以下の数値データ」を全て取り出したいです。
その場合,どのようにすればよろしいでしょうか。
フォルダ内にはファイルが100近くあり,matlabで処理したく思っています。
ご検討,よろしくお願いいたします。

采纳的回答

Hernia Baby
Hernia Baby 2022-8-24
编辑:Hernia Baby 2022-8-24
以下のように条件をあてはめて一つ一つをセルに入れるようにしました。
files = dir('*.xlsx');
for ii = 1:length(files)
tmp = readmatrix(files(ii).name));
idx = tmp(:,3) > 0 & tmp(:,3) <= 5;
A{ii,1} = tmp(idx,3);
end
  1 个评论
Hiroki Takeda
Hiroki Takeda 2022-8-24
早速に教えていただきまして誠にありがとうございました。
大変助かりました。

请先登录,再进行评论。

更多回答(1 个)

Atsushi Ueno
Atsushi Ueno 2022-8-24
MATLABだと、データストアを用いて串刺し集計が出来ます。
適当なサンプルファイルを添付し要求通り読み込んでみました。
path = pwd; % Excelファイル一式があるフォルダのパス(この例はカレントフォルダ)
ssds = spreadsheetDatastore(path)
Warning: Table variable names that were not valid MATLAB identifiers have been modified. Since table variable names must be unique, any table variable names that happened to match the new identifiers also have been modified.
ssds =
SpreadsheetDatastore with properties: Files: { '/users/mss.system.seAwNr/Book1.xlsx'; '/users/mss.system.seAwNr/Book2.xlsx'; '/users/mss.system.seAwNr/Book3.xlsx' } Folders: { '/users/mss.system.seAwNr' } AlternateFileSystemRoots: {} Sheets: '' Range: '' Sheet Format Properties: NumHeaderLines: 0 VariableNamingRule: 'modify' ReadVariableNames: true VariableNames: {'ColumnA', 'ColumnB', 'ColumnC' ... and 2 more} VariableTypes: {'double', 'double', 'double' ... and 2 more} Properties that control the table returned by preview, read, readall: SelectedVariableNames: {'ColumnA', 'ColumnB', 'ColumnC' ... and 2 more} SelectedVariableTypes: {'double', 'double', 'double' ... and 2 more} ReadSize: 'file' OutputType: 'table' RowTimes: [] Write-specific Properties: SupportedOutputFormats: ["txt" "csv" "xlsx" "xls" "parquet" "parq"] DefaultOutputFormat: "xlsx"
ssds.Sheets = "指定のシート"; %「それぞれのファイルの指定のシートのC列」を選択
ssds.SelectedVariableNames = "ColumnC"; %「それぞれのファイルの指定のシートのC列」を選択
value = readall(ssds);
value = value.ColumnC(value.ColumnC > 0 & value.ColumnC <= 5) %「0より大きく5以下の数値データ」を全て取り出したいです。
value = 3×1
3.8349 3.0337 2.6251

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!