- You have files (referred to as ‘subjects’ by you) named as ‘sub1’, ‘sub2’ , …, ‘sub44’.
- Each file has multiple columns (you have referred to them as ‘features’).
- You want to loop through the 44 files and extract certain features from each file.
How to read different features from multiple subjects?
1 次查看(过去 30 天)
显示 更早的评论
I have 44 subjects with name sub1 to sub44. I want to extract various features from the matlab double format. Kindly guide me how to design the loop to execute the files so that I can extract the whole features by using a single loop. Thanking in advance !!
0 个评论
回答(1 个)
Zinea
2024-2-22
Based on my understanding of the question:
You can refer to the example code below where I have taken the case if you want to extract features corresponding to say, column 2 and column 4:
% Preallocate cell arrays to store the extracted features
feature2 = cell(44, 1);
feature4 = cell(44, 1);
% Loop through each file
for i = 1:44
% Construct the filename
filename = sprintf('sub%d', i);
% Load the data from the file
data = load(filename);
% Extract feature2 and feature4
feature2{i} = data(:, 2); % Extract the second column
feature4{i} = data(:, 4); % Extract the fourth column
end
After the loop, the cell arrays feature2 and feature4 will contain the extracted features from all the files.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!