MATLAB: How to find the index of the line to find the occurrence of perticular character

statisticsStatistics and Machine Learning Toolboxtoolbox

Hi
I have multiple text files, and am reading. But I want to find the number lines in a text files(s), and also find the occurrence of dotted line(s)'——'. I use the following code, but I am unable to find the index of the dotted lines(s).My code giving 'Zero'. In fact the first dotted line occurs at line number 23 (row number), and the second dotted lines is occurring at line number 41 (row number). Please help me how can I do this.
clc;clear all;
clc
tic
FileList=dir('D:\Mekala_Backupdata\Matlab2010\Filesfolder\Try2/');
j=1;
for i=3:1:(size(FileList)) %%read all files from folder of specified dir
FileName{j}=FileList(i).name;
j=j+1;
end
% fid = fopen('yourFile.ext');
for j=1:size(FileName,2)
fid=fopen(['D:\Mekala_Backupdata\Matlab2010\Filesfolder\Try2/',FileName{j}],'r'); %%opening each files and read each line
allText = textscan(fid,'%s','delimiter','\n');
numberOfLines = length(allText{1});
fclose(fid)
end
[~,indx]=ismember('----+',FileName,'rows');

Best Answer

Try this:
filename = 'RainFallReport1.txt'
fid = fopen(filename);
thisLine = fgetl(fid);
linesRead = 1;
dashedLineIndexes = [];
while ischar(thisLine)
disp(thisLine) % Comment out to not echo to command window.
if ~isempty(strfind(thisLine, '-----------------------'))
dashedLineIndexes = [dashedLineIndexes, linesRead];
end
linesRead = linesRead + 1;
thisLine = fgetl(fid);
end
fclose(fid);
fprintf('\n\nTotal number of lines in file "%s" = %d.\n', filename, linesRead);
fprintf('Dashes found on line(s):\n');
fprintf(' %d.\n', dashedLineIndexes);