필터 지우기
필터 지우기

Smoothing for multiple csv files

조회 수: 5 (최근 30일)
Oliver Steiner
Oliver Steiner 2023년 2월 20일
편집: Mathieu NOE 2023년 3월 6일
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에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by