Textscan to extract data from text file
4 次查看(过去 30 天)
显示 更早的评论
This is a followup to a previous question I posted here. In my original question I forgot to mention that I also need to extract the following lines from each specimen in the same pass/loop:
Width: 0.5040000 in
Thickness: 0.0350000 in
Spec gauge len: 7.0000000 in
Ext. gauge len: 8.5000000 in
My attempts to modify the code provided by dpb (below) result in the error "Subscripted assignment dimension mismatch"
fid=fopen('Sample_DATA.TXT','r'); % open file
N=cell2mat(textscan(fid,'Number of specimens: %d %*[^\n]','headerlines',11));
for i=1:N % loop over number specimens in file
l=fgetl(fid); % initialize string to find start of section
while isempty(strfind(l,'Specimen:')),l=fgetl(fid);end % find the Specimen: n start
while isempty(strfind(l,'_')), l=fgetl(fid);end % then line break before data
d(i)=textscan(fid,'','delimiter',',','collectoutput',1); % the nth specimen data set
end
fid=fclose(fid);
Any suggestions? The text file is attached.
2 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!