MATLAB Answers

0

"Subscripted assignment dimension mismatch"?

Akhila 님이 질문을 제출함. 18 Feb 2015
최근 활동 Akhila 님이 댓글을 추가함. 19 Feb 2015
I'm unable to figure out where this error is coming about in this block of code. Any help would be great. Thank you.
%%Write data to a file (requires writeM2T.m)
cnt=0;
cnt2=0;
ind = [1 2 3 4 5 -win:win];
for i=1:length(Ndya)
for j=1:Nepi
if ~isempty(data(i,j).MOM)
if ~isempty(data(i,j).BABY)
cnt=cnt+1;
OUTcrqa(cnt,:) = [i j data(i,j).crqa];
OUTlagp(cnt,:) = [i j data(i,j).crqaBS];
for k = 1:max(size(data(i,j).crqaCI))
cnt2=cnt2+1;
OUTcrqaCI(cnt2,:) = [i j data(i,j).crqaCI(k,:) ind(k)];
end
end
end
end
end
cd(yourpath)
save('CRQAoutput.mat')
hdr1={'dyad','episode','RR','DET','<L>','Lmax','ENTR','LAM','TT','Vmax','T1','T2','RTE','Clust','Trans'};
writeM2T(OUTcrqa,'outCRQA.dat',hdr1,[],[],'w')
%hdr2=[{'dyad','episode'} {num2cell(-win:win)}];
writeM2T(OUTlagp,'outLAGPcrqad.dat',[],[],[],'w')
% Bootstrapped CI
hdr3={'dyad','episode','CI_U','CI_L','Measure'};
writeM2T(OUTcrqaCI,'outBSCI.dat',hdr3,[],[],'w')

  댓글 수: 8

표시 이전 댓글 수: 5
Sure, this is the entire code. All the sections prior to the last one are running fine.
%% INITIATE VARIABLES
% Set the path to where the data are (assuming there are mom and baby subfolders) yourpath = 'C:\Users\Akhila\Documents\MATLAB\TS16W\TS16WDyads';
%This is a vector of the dyad numbers to analyze Ndya = {'0115','0126','0132','0162','0181','0194','0206','0226','0241','0252','0254','0255','0259','0261','0268','0274','0287','0294','0296','0297','0299','0300','0303','0305','0310','0311','0312','0319','0326','0329','0342','0355','0364','0371','0372','0381','0384','0386','0398','0399','0401','0424','0427','0436','0443','0446','0477','0488','0490','0493','0494','0507','0510','0520','0527','0530','0531','0537','0549','0554','0555','0568','0616','0624','0642','0670','0686','0719'};
%Enter the max. number of episodes to analyze Nepi = 5;
% CRQA settings dim = 3; lag = 10; rr = .10; lmin = 2; vmin = 2; tw = 1; win = 15;
% Strings to generate filename prefix ='TS16W'; midMOM ='0SF_E'; midBABY ='1SF_E'; suffix = '.txt';
%% READ DATA
for i=1:length(Ndya) for j=1:Nepi
data(i,j).dyad = Ndya{i};
data(i,j).episode = j;
cd([yourpath]);
filename = [prefix,Ndya{i},midMOM,num2str(j),suffix];
if exist(filename,'file')
data(i,j).MOM.raw = importdata(filename);
data(i,j).MOM.ID = filename;
cd([yourpath]);
filename = [prefix,Ndya{i},midBABY,num2str(j),suffix];
data(i,j).BABY.raw = importdata(filename);
data(i,j).BABY.ID = filename;
end
end
end
% Save the data so far cd(yourpath) save('CRQAoutput.mat')
%% PERFORM CRQA(D)
Nboot = 2500; Exceptions = 0; Warnings = 0;
fprintf('\n') disp('------Start CRQA analysis------') fprintf('\n')
for i=1:length(Ndya) for j=1:Nepi
if ~isempty(data(i,j).MOM)
if ~isempty(data(i,j).BABY)
fprintf('\n')
fprintf('Dyad: %s, Episode %u',Ndya{i},j);
fprintf('\n')
if length(data(i,j).MOM.raw)>length(data(i,j).BABY.raw)
data(i,j).MOM.raw(length(data(i,j).BABY.raw)+1:length(data(i,j).MOM.raw))=[];
fprintf('\n')
disp('WARNING: Timeseries unequal length... trimming')
fprintf('\n')
Warnings = Warnings +1;
end
if length(data(i,j).BABY.raw)>length(data(i,j).MOM.raw)
data(i,j).BABY.raw(length(data(i,j).MOM.raw)+1:length(data(i,j).BABY.raw))=[];
fprintf('\n')
disp('WARNING: Timeseries unequal length... trimming')
fprintf('\n')
Warnings = Warnings +1;
end
try
% Rescale to max distance
data(i,j).MOM.maxd = (100*data(i,j).MOM.raw)./pss(data(i,j).MOM.raw,dim,lag,'maxnorm');
data(i,j).BABY.maxd = (100*data(i,j).BABY.raw)./pss(data(i,j).BABY.raw,dim,lag,'maxnorm');
% CRP
data(i,j).crp = crp(data(i,j).MOM.maxd,data(i,j).BABY.maxd,dim,lag,rr,'rr','nonormalize','nogui');
% CRQA
data(i,j).crqa= crqa(data(i,j).MOM.maxd,data(i,j).BABY.maxd,dim,lag,rr,[],[],lmin,vmin,tw,'rr','nonormalize','nogui');
% Get CI by Bootstrapping
disp('Bootstrapping CRQA...')
[data(i,j).crqaBS,data(i,j).crqaCI,data(i,j).crqaCIlabels] = rqaci(data(i,j).crp,Nboot,5,tw,lmin,vmin,win);
if max(size(data(i,j).crp)) > 2*win
% Get diagonal profile using crqad (produces same output for RR as rqaci.m)
data(i,j).lagprof = crqad(data(i,j).MOM.maxd,data(i,j).BABY.maxd,dim,lag,rr,win,'rr','nonormalize','nogui');
else
fprintf('\n')
disp('WARNING: RP is too small for lag window!!!')
fprintf('\n')
Warnings = Warnings +1;
end
catch ME
ME
Exceptions = Exceptions + 1;
end
end
end
end
end
fprintf('\n') fprintf('Finished with %u exception(s)',Exceptions); fprintf('\n') fprintf('Finished with %u warning(s)',Warnings); fprintf('\n') fprintf('See Command Window for details'); fprintf('\n') fprintf('\n') disp('------Finished CRQA analysis------') fprintf('\n')
% Save data cd(yourpath) save('CRQAoutput.mat')
%% Write data to a file (requires writeM2T.m) cnt=0; cnt2=0; ind = [1 2 3 4 5 -win:win]; for i=1:length(Ndya) for j=1:Nepi
if ~isempty(data(i,j).MOM)
if ~isempty(data(i,j).BABY)
cnt=cnt+1;
OUTcrqa(cnt,:) = [i j data(i,j).crqa];
OUTlagp(cnt,:) = [i j data(i,j).crqaBS];
for k = 1:max(size(data(i,j).crqaCI))
cnt2=cnt2+1;
OUTcrqaCI(cnt2,:) = [i j data(i,j).crqaCI(k,:) ind(k)];
end
end
end
end
end
cd(yourpath) save('CRQAoutput.mat')
hdr1={'dyad','episode','RR','DET','<L>','Lmax','ENTR','LAM','TT','Vmax','T1','T2','RTE','Clust','Trans'}; writeM2T(OUTcrqa,'outCRQA.dat',hdr1,[],[],'w')
%hdr2=[{'dyad','episode'} {num2cell(-win:win)}]; writeM2T(OUTlagp,'outLAGPcrqad.dat',[],[],[],'w')
% Bootstrapped CI hdr3={'dyad','episode','CI_U','CI_L','Measure'}; writeM2T(OUTcrqaCI,'outBSCI.dat',hdr3,[],[],'w')
I cannot run this... there are files missing for me... Can you send all I need to run the hole thing!
Hi Erik, Attached is the whole folder. The .m file has the MATLAB code.

로그인 to comment.

태그

답변 수: 2

Erik S. 님의 답변 18 Feb 2015

Your sturcture data only contains the fields "dyad" and "episode" not "MOM" or "BABY"
When you get to line 67 the program crashes.

  댓글 수: 1

aah, but won't the declarations in line 38, 39, 42, 43 suffice?

로그인 to comment.


Erik S. 님의 답변 18 Feb 2015

Those lines 38-43 are never executed. The files you are looking for is in another folder than you .m file. Try to move them to the same folder.

  댓글 수: 8

표시 이전 댓글 수: 5
Subscripted assignment dimension mismatch - this is the original error I was getting in the last block. What is the error in line 154?
Also, i get 30 warnings, no exceptions.
The exceptions occurs because the function pss is undefined for arguments of type double it says. Is pss a function or a variable?
The error is:
Reference to non-existent field 'crqa'.
Error in TS16WCode (line 154) OUTcrqa(cnt,:) = [i j data(i,j).crqa];
i'm not getting those exceptions, so not sure what you are asking. I'm going to try some other things. Thank you for your help. I will be in touch if I can clarify the question further.

로그인 to comment.



Translated by