Merging different cell arrays

2 次查看(过去 30 天)
Ramiro Rea
Ramiro Rea 2017-4-3
回答: ES 2017-4-3
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

回答(1 个)

ES
ES 2017-4-3
%%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

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by