How to read different features from multiple subjects?

1 view (last 30 days)
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 !!

Answers (1)

Zinea
Zinea on 22 Feb 2024
Based on my understanding of the question:
  1. You have files (referred to as ‘subjects’ by you) named as ‘sub1’, ‘sub2’ , …, ‘sub44’.
  2. Each file has multiple columns (you have referred to them as ‘features’).
  3. You want to loop through the 44 files and extract certain features from each file.
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.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!