matrix index is out of range for deletion
Afficher commentaires plus anciens
sorry for posting again.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!
Réponses (1)
Walter Roberson
le 24 Juil 2015
0 votes
E{k}=[x{1,k}{2} x{1,k}{3} x{1,k}(4)]; is creating a cell array, but afterwards in the "for" loop you are treating E as a numeric array.
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!