Index exceeds matrix dimensions

1 view (last 30 days)
venuuu
venuuu on 3 Apr 2015
Commented: Rena Berman on 17 Jan 2018
I've got a problem and because of my bad knowledge of matlab, it would be great if someone know the solution for this problem.
arr = {'01', '02', '03', '04'};
ldir = '/data/.....'
cond= {Forstats_1PLhann.mat};
savedir = ldir;
for i= 1:11;
display (sprintf('analysing subject....%s,arr{i}));
subjectdir=strcat(ldir, 'Tsbj_', arr{i},'/');
load(strcat(subjectdir,cond {1}));
data{1,i} = ft_freqdescriptives ([], PLhann);
clear PLhann
end;
cond= {Forstats3_PLhann.mat'};
for i = 12:22
display (sprintf('analysing subject....%s,arr{i}));
subjectdir=strcat(ldir, 'Tsbj_', arr{i},'/');
load(strcat(subjectdir,cond {1}));
data{1,i} = ft_freqdescriptives ([], PLhann);
clear PLhann end;
ERROR: Index exceeds matrix dimensions
  2 Comments
Ilham Hardy
Ilham Hardy on 3 Apr 2015
Please post the complete error message (do not trim the error message).
Rena Berman
Rena Berman on 17 Jan 2018
(Answers Dev) Restored edit

Sign in to comment.

Answers (1)

Ingrid
Ingrid on 3 Apr 2015
Edited: Ingrid on 3 Apr 2015
your array only contains four elements (first line of your code) in your loop you are trying to acces arr{i} where i goes from 1:11 this gives you the error message that the index exceeds matrix dimensions when the loop goes to i=5 because arr{5} does not exist so you have to change
for i = 1:4
OR define
arr = {'01', '02', '03', '04','05','06','07','08','09','10','11'};
depending on which one is applicable for your case

Community Treasure Hunt

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

Start Hunting!