Effacer les filtres
Effacer les filtres

Merging different cell arrays

2 vues (au cours des 30 derniers jours)
Ramiro Rea
Ramiro Rea le 3 Avr 2017
Réponse apportée : ES le 3 Avr 2017
Hi everyone,
I'm working with some cell arrays. Each one of them belongs to a set of trial in an experiment, but I want to merge them to create a file with all the results for each participant. Each array has 3 columns and 10 rows. I want to create a loop that merges all the blocks of each participant, save the merged data and then continue with next subject. I know probably this is not that hard, but I am quite new to this. Hope this makes sense. Thanks for your help.
Right now I'm stuck like this
%%Number of files to merge.
NumberOfDataset = 18;
for i = 1:NumberOfDataset
% get allfiles matching the pattern '(i)_MID.mat'
files = dir(sprintf('%d_MID.mat',i));
a = load(files);
%Perform some calculations on dataset
C1 = data_N;
C2 = data_P1;
C3 = data_P2;
C4 = data_R1;
C5 = data_R2;
%merge all in a single cell array
mergeddata = [C1;C2;C3;C4;C5];
%save the merged array
filename = [ 'mergedsubject_' num2str(i) '.mat' ];
end

Réponses (1)

ES
ES le 3 Avr 2017
%%Number of files to merge.
NumberOfDataset = 18;
for i = 1:NumberOfDataset
% get allfiles matching the pattern '(i)_MID.mat'
files = dir(sprintf('%d_MID.mat',i));
a = load(files);
%Perform some calculations on dataset
C1 = data_N;
C2 = data_P1;
C3 = data_P2;
C4 = data_R1;
C5 = data_R2;
%merge all in a single cell array
mergeddata = {C1;C2;C3;C4;C5}; %Creating Cell Array Here
%save the merged array
filename = [ 'mergedsubject_' num2str(i) '.mat' ];
%Save the mat file here
end

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by