Textscan to extract data from text file

조회 수: 1 (최근 30일)
Zekeftw
Zekeftw 2016년 8월 1일
편집: per isakson 2016년 8월 1일
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