Smoothing for multiple csv files

5 vues (au cours des 30 derniers jours)
Oliver Steiner
Oliver Steiner le 20 Fév 2023
Modifié(e) : Mathieu NOE le 6 Mar 2023
Hi! I smoothed some data for an experiment for one partipants, now I want to do that for multiple participants and save this to a table. Can you sopport me with this? Thanks. The code for one participant looks like this:
% Set the filename
filename = 'P01.xlsx';
% Import the data from the Xlsx file
data = xlsread(filename);
% assess the data
y = (data(:,1));
x = (data(:,5));
% Now I will smooth the data after the minimal pupil size
smoothdata = round(smooth(x(380:2000),y(380:2000),0.1,'loess'))
% Combine the smoothed data with the real data
combinedData = [y(1:379);smoothdata]
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 20 Fév 2023
You can run the code through a for loop and save the data in a table according to the number of participants.

Connectez-vous pour commenter.

Réponse acceptée

Mathieu NOE
Mathieu NOE le 6 Mar 2023
Modifié(e) : Mathieu NOE le 6 Mar 2023
hello
xlsread is a bit outdated , you could try more recent alternatives (readtable, readcell , readmatrix,...)
suggestion below (a simple for loop)
you can improve the sorting process by using this Fex submission (the native dir function is not perfect for that)
the result is stored as a cell array (combinedData{k})
but you can also use vertical or horizontal concatenation if the data has always same size
fileDir = pwd; % current directory (or specify which one is the working directory)
S = dir(fullfile(fileDir,'P*.xlsx')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order , see :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
for k = 1:length(S)
filename = S(k).name % to actually show filenames are sorted (see command window)
% Import the data from the Xlsx file
data = readmatrix(fullfile(fileDir, filename));
% assess the data
y = (data(:,1));
x = (data(:,5));
% Now I will smooth the data after the minimal pupil size
smoothdata = round(smooth(x(380:2000),y(380:2000),0.1,'loess'))
% Combine the smoothed data with the real data
combinedData{k} = [y(1:379);smoothdata]
end

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by