How to load multiple files and calculate value for each file (with same formula)
11 views (last 30 days)
In case that I have the separate 123 mat files (bearing1_1_1.mat to bearing 1_1_123.mat) and I would like to calculate RMS and Crest Factor of each file (i.e., RMS for bearing1_1_1 = xxxxx, CF for bearing1_1_1 = xxxxx). How to write the code?
PS. I already have code for RMS and CF calculation but I only want how to calculate them (all 123 file) in one execution.
Because now I have to do it manually file by file and it consums lot of times (i.e., run bearing1_1_1.mat and go to next data)
Thanks for your kind supports
Mathieu NOE on 25 Apr 2022
this is the code (principle) to load all the mat files in a loop
% use the structure returned by DIR:
P = cd; % working directory
S = dir(fullfile(P, 'bearing*.mat'));
for k = 1:numel(S)
S(k).folder % fyi
S(k).name % fyi
F = fullfile(S(k).folder, S(k).name);
%S(k).data = load(F); % or READTABLE or whatever.
S(k).data = load(F);
% % structure S: it contains all of your file data and the corresponding filenames
% % For example, the 2nd filename and its data: