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

조회 수: 12 (최근 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!