Hi all,
I have a text file (.inp) from Abaqus, where I need to find the line number of some strings. I read the file using 'fopen' and 'textscan' into MATLAB, results in string cells. The file looks like this:
rawInpStrrawInpStr = 1×1 cell array {1557×1 cell}rawInpStr{:} = {'*Heading' } {'** Job name: l9h2SingleInc Model name: Model-1' } {'** Generated by: Abaqus/CAE 6.12-4' } {'*Preprint, echo=NO, model=NO, history=NO, contact=NO' } {'** PARTS' } {'*Part, name=beam' } {'*End Part' } {'** ASSEMBLY' } {'*Assembly, name=Assembly' } {'*Instance, name=beam-1, part=beam' } {'*Node' } ......
For example, if I need to find 3 lines matching '** Job name', '** PARTS', '*End Part', I write:
for iStr = 1:length(rawInpStr{1}) strComp = strtrim(rawInpStr{1}{iStr}); if length(strComp) > 10 if strcmp(strComp(1:11), '** Job name') == 1 loc1 = iStr; end end if length(strComp) > 7 if strcmp(strComp(1:8), '** PARTS') == 1 loc2 = iStr; end end if length(strComp) > 8 if strcmp(strComp(1:9), '*End Part') == 1 loc3 = iStr; end endend
So for N strings I'd want to find, I need N for loops. Is there a more elegant way to do this?
Best Answer