How to read different features from multiple subjects?

1 visualizzazione (ultimi 30 giorni)
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 !!

Risposte (1)

Zinea
Zinea il 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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by