How to append values from different files to an array?

2 ビュー (過去 30 日間)
Fraser Barnard
Fraser Barnard 2021 年 3 月 1 日
回答済み: Jan 2021 年 3 月 1 日
Hello, I have a script that reads in a signal and finds the mean intensity from it. I have hundreds of these files and each time I run I would like to add the next mean value to an array. The files are CSV's and the code is edited each time to call a new file.
data=load('600-0.csv'); %filename changed every time and ran again
V=data(:,1);
M=mean(V);
% I have tried using this, however this overwrites each time.
mean=[]
mean = [mean; M]
Thank you for help. I have spent a lot of time trying to find a solution before posting here.

採用された回答

Jan
Jan 2021 年 3 月 1 日
Do not use "mean" as name of a variable, because then you cannot use the function mean() anymore.
Folder = 'C:\Your\Folder';
FileList = dir(fullfile(Folder, '*.csv'));
MeanData = zeros(1, numel(FileList)); % Pre-allocation!!!
for iFile = 1:numel(FileList)
aFile = fullfile(Folder, FileList(iFile).name);
Data = load(aFile);
MeanData(iFile) = mean(Data(:, 1));
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Attributes and Indexing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by