Create a cicle 'for' to create multiple fields

3 views (last 30 days)
Rita Barnabé
Rita Barnabé on 9 Nov 2021
Commented: Rita Barnabé on 12 Nov 2021
data.C028 = importdata('C028 S1.mat');
data.C028 = data.C028.data;
ecg_C028 = data.C028(:,6);
% File 2/5
data.C022 = importdata('C022 S1.mat');
data.C022 = data.C022.data;
ecg_C022 = data.C022(:,6);
% File 3/5
data.C008 = importdata('C008 S1.mat');
data.C008 = data.C008.data;
ecg_C008 = data.C008(:,6);
% File 4/5
data.C006 = importdata('C006 S1.mat');
data.C006 = data.C006.data;
ecg_C006 = data.C006(:,6);

Accepted Answer

Benjamin
Benjamin on 9 Nov 2021
data = struct();
fn = {'C028' 'C022' 'C008' 'C006'};
for i = 1:numel(fn)
data.(fn{i}) = getfield(importdata([fn{i} ' S1.mat']),'data');
end

More Answers (0)

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!