Import data into matlab but ignore subject name
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I've been using this code to import data from my directory into a matlab structure. Data is saved in a way that each csv-file is saved in a subfolder that is named according to the subject ID. It has always worked quite well because the files in the subfolders were named identically, but now I ran into a problem since the names of the files that I am wanting to import (' the name of the file that you want.csv') include the subject name (before all were named data_matrix.csv but now they are named subject_1_data_matrix.csv, subject_2_data_matrix.csv etc.). Is there an easy way to ignore the subject-specific information in the name of the data? Maybe a placeholder?
Thanks!
Johanna
P = 'absolute or relative path to where the subfolders are';
N = 'the name of the file that you want.CSV';
S = dir(fullfile(P,'*'));
S = S([S.isdir]); % remove files
S(ismember({S.name},{'.','..'})) = []; % remove dot directories
for k = 1:numel(S) % loop over the subfolders
F = fullfile(P,S(k).name,N);
S(k).data = readmatrix(F);
end
0 件のコメント
採用された回答
Stephen23
2022 年 4 月 1 日
P = 'absolute or relative path to where the subfolders are';
S = dir(fullfile(P,'**','*data_matrix.CSV'));
for k = 1:numel(S) % loop over the files
F = fullfile(S(k).folder,S(k).name);
S(k).data = readmatrix(F);
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!