Textscan to extract data from text file

2 views (last 30 days)
Zekeftw
Zekeftw on 1 Aug 2016
Edited: per isakson on 1 Aug 2016
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 Comments
Walter Roberson
Walter Roberson on 1 Aug 2016
How did you initialize d ?
Which line is the error occurring on?
Zekeftw
Zekeftw on 1 Aug 2016
Edited: Zekeftw on 1 Aug 2016
Sorry for the confusion. The code above is working fine for that it's meant to do (extract the 500+ rows of data for each specimen).
I am trying to modify it so that it also extracts (lines 54-57 for specimen 1)
Width: 0.5040000 in
Thickness: 0.0350000 in
Spec gauge len: 7.0000000 in
Ext. gauge len: 8.5000000 in
for each specimen and saves it to a cell array. Similar to d.
The errors occured when I tried to modify it.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!