Delete the rows with its first character other than a number and copy all the other rows into a new file.

1 vue (au cours des 30 derniers jours)
I want to delete the rows with the first character other than a number and copy the other rows which has it's first as a number into a new file.
For ex . my file looks like this
Mach-1 asrt asrj ssrj . . . 0346 1346 2346 3334 4337 . . . aaerh baer daer frah . . . 1345 2346 3436 4346 . . . asdh bsth
I only wan the lines which starts with a number
  2 commentaires
Michael Haderlein
Michael Haderlein le 29 Juil 2014
That sounds as if you want to solve this again, although it was extensively answered by Azzi Abdelmalek and me (<http://www.mathworks.de/matlabcentral/answers/143308-i-have-to-detect-the-startrow-and-endrow-from-a-file-automatically-from-a-txt-file)>. In case it's the same question, please respond in the other thread.
In case it's a different question because now your file has numbers and text mixed:
fid=fopen(filename);
curline=fgetl(fid);
result=[];
while ischar(curline)
if ~isempty(curline) && ~any(isstrprop(curline,'alpha'))
result=[result;str2num(curline)];
end
curline=fgetl(fid);
end
fclose(fid);
Vinit
Vinit le 29 Juil 2014
sir .... both the programs works perfectly for me.... i have
one more problem which i will post it as another question.... Thank you for your time

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 29 Juil 2014
Modifié(e) : Azzi Abdelmalek le 29 Juil 2014
fid = fopen('file.txt');
a=textscan(fid,'%s')
fclose(fid);
b=a{:};
c=b(cellfun(@(x) ~isempty(regexp(x,'^\d','match')),b))
To export the new data to a new file
fileID = fopen('file1.txt','w');
for k=1:numel(c)
fprintf(fileID,'%s \n',c{k});
end
fclose(fileID);

Plus de réponses (0)

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by