フィルターのクリア

Smoothing for multiple csv files

4 ビュー (過去 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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by