フィルターのクリア

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

18 ビュー (過去 30 日間)
Hiroki Takeda
Hiroki Takeda 2022 年 8 月 24 日
回答済み: Atsushi Ueno 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!