matrix index is out of range for deletion

1 view (last 30 days)
I have very large number of text files( each text file is n rows by 4 column and the first column is string) in the directory and i want to export each one by one and excute. For this i write the following code:
d=dir('*.txt');
n=length(d);
x=cell(1,n);
E=cell(1,n);
for k=1:n;
fid=fopen(d(k).name,'rt');
x{k}= textscan(fid, '%s%f%f%f');
fclose(fid);
A=x{1,k}{1};
E{k}=[x{1,k}{2} x{1,k}{3} x{1,k}(4)];
end
st={'bp','mo','ag','sh'};
for j=1:length(st)
E(strncmp(A,st(j),2),:)=[];
A(strncmp(A,st(j),2),:)=[];
E(abs(E(:,3))>30,:)=[];
end
For a single text file the code works. But for multiple file it gives the error message *matrix index is out of range for deletion*.Any solution Ps. Thanks!

Answers (1)

Star Strider
Star Strider on 23 Jul 2015
I can’t be certain, but it’s possible that the strncmp call is returning an empty array. That would throw that error.
  2 Comments
gustavo sanchez
gustavo sanchez on 23 Jul 2015
Thanks. But i couldn't manage to fix it.
Star Strider
Star Strider on 23 Jul 2015
If you insert this line as the first statement in your for loop, what does it return?
T1 = strncmp(A,st(j),2)
If it is empty, that is likely your problem.
I can’t run your code, so you may need to use the debug features in the Editor to find the problem.

Sign in to comment.

Categories

Find more on Cell Arrays 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!