import many txt files
古いコメントを表示
Hi, I have many text files about 16574, I need to import them to matlab and calculate the average of each files.
回答 (2 件)
dpb
2017 年 2 月 22 日
0 投票
2 件のコメント
malihe keykhai
2017 年 2 月 23 日
Jan
2017 年 2 月 23 日
@malihe keykhai: Thanks for posting, what you have done so far. The code contains some problems: "csvread('Files')" tries to read the file names 'Files'. mean(Files) tries to calculate the average of the struct Files created by the dir() command, and this must fail. See my answer.
Jan
2017 年 2 月 23 日
Folder = pwd:
Files = dir(fullfile(Folder, '*.txt'));
Result = cell(1, numel(Files));
for j = 1:numel(Files)
aFile = fullfile(Folder, Files(j).name);
Data = csvread(aFile);
Result{j} = mean(Data, 1);
end
The question remains, what "average of each files" exactly mean. Here the mean() along the first dimension is calculated and stored in a cell. But perhaps you want something else.
2 件のコメント
malihe keykhai
2017 年 2 月 23 日
Jan
2017 年 2 月 23 日
I do not understand your question. My current code creates a cell, which contains the vector with the mean of each file: Result{k} contains the mean of Files(k).name. Is this what you need?
カテゴリ
ヘルプ センター および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!