Smoothing for multiple csv files

4 次查看(过去 30 天)
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 个评论
Dyuman Joshi
Dyuman Joshi 2023-2-20
You can run the code through a for loop and save the data in a table according to the number of participants.

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2023-3-6
编辑:Mathieu NOE 2023-3-6
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by