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

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

Réponse acceptée

Hernia Baby
Hernia Baby le 24 Août 2022
Modifié(e) : Hernia Baby le 24 Août 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 commentaire
Hiroki Takeda
Hiroki Takeda le 24 Août 2022
早速に教えていただきまして誠にありがとうございました。
大変助かりました。

Connectez-vous pour commenter.

Plus de réponses (1)

Atsushi Ueno
Atsushi Ueno le 24 Août 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

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!