필터 지우기
필터 지우기

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