Textscan to extract data from text file

3 次查看(过去 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 个评论
Walter Roberson
Walter Roberson 2016-8-1
How did you initialize d ?
Which line is the error occurring on?
Zekeftw
Zekeftw 2016-8-1
编辑:Zekeftw 2016-8-1
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.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by