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

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

Accepted Answer

Hernia Baby
Hernia Baby on 24 Aug 2022
Edited: Hernia Baby on 24 Aug 2022
以下のように条件をあてはめて一つ一つをセルに入れるようにしました。
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 Comment
Hiroki Takeda
Hiroki Takeda on 24 Aug 2022
早速に教えていただきまして誠にありがとうございました。
大変助かりました。

Sign in to comment.

More Answers (1)

Atsushi Ueno
Atsushi Ueno on 24 Aug 2022
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

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!