Merging different cell arrays
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
ES
on 3 Apr 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
0 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!