Help in Strcut MATLAB , please !
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have this code: for build struct in Matlab to read text file :
when i running this code gave me error because the third line of the text data file ( c) , is not arranged in the same style as others text lines data file; please i need read this text file as struct with ignore reading the third data line in text file or any line similar to the third data line has not appropriate arrangement as other data lines in that text file
c={'413733000: system.cpu15.icache: ReadReq [10574:10577] IF hit state: 5 (S) valid: 1 writable: 0 readable: 1 dirty: 0 tag: 8',...
'413733000: system.cpu00.icache: ReadReq [6e4ef8:6e4efb] IF hit state: 5 (S) valid: 1 writable: 0 readable: 1 dirty: 0 tag: 372',...
'245975500: system.cpu01.icache: Found addr 0x8cc0 in upper level cache for snoop WritebackClean [8cc0:8cff] from lower cache',...
'243241000: system.cpu00.dcache: WriteReq [8589b8:8589bf] hit state:f (M) valid: 1 writable: 1 readable: 1 dirty: 1 tag: 42c'};
out=struct;
for n=1:numel(c)
tline(n)= strlength(c(n));
if (tline(n) >= 123)|| (tline(n) <= 126)
str=c{n};
idx=strfind(str,':');
ID=str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off ID
idx=strfind(str,':');
CPU=str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off CPU
idx1=strfind(str,'[');idx1=idx1(1)+1;
idx2=strfind(str,']');idx2(idx2<idx1)=[];idx2=idx2(1)-1;
MemoryAddress=str(idx1:idx2);
str(1:(idx2+2))='';%chop off MemoryAddress
%etc
idx=strfind(str,':');
Hits=str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off hits
idx=strfind(str,':');
Hitsnum =str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off hits
idx=strfind(str,':');
writeable =str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off hits
idx=strfind(str,':');
readable =str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off hits
idx=strfind(str,':');
dirty=str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off hits
idx=strfind(str,':');
tags=str(1:(idx(1)-1));
str(1:(idx(1)+1))='';%chop off hits
%store to output struct
out(n).ID=ID;
out(n).CPU=CPU;
out(n).MemoryAddress=MemoryAddress;
out(n).Hits=Hits;
out(n).Hitsnum=Hitsnum;
out(n).writable=writeable;
out(n).readable=readable;
out(n).dirty=dirty;
out(n).tags=tags;
else
end
end
1 Kommentar
Walter Roberson
am 22 Aug. 2019
I recommend using regexp() to parse the file, using the named token feature.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!