이것은 데이터의 일부입니다.
GLOBAL DOF SET =
1 3 4 5 6 33 35 36 37 38
65 67 68 69 70 97 99 100 101 102
129 131 132 133 134 161 163 164 165 166
GLOBAL DOF SET NODES, LABELS =
1 UX 1 UZ 2 UX 2 UZ 3 UX
3 UZ 4 UX 4 UZ 5 UX 5 UZ
6 UX 6 UZ 7 UX 7 UZ 8 UX
8 UZ 9 UX 9 UZ 10 UX 10 UZ
11 UX 11 UZ 12 UX 12 UZ 13 UX
13 UZ
MASS INFORMATION:
TOTAL MASS = 12197.
CENTROID (X,Y,Z) = 30.000 0.0000 8.5809
MOMENT OF INTERTIA ABOUT ORIGIN:
IXX = 0.10651E+07 IYY = 0.18383E+08 IZZ = 0.17318E+08
IXY = 0.0000 IYZ = 0.0000 IZX =-0.31397E+07
GLOBAL DOF SET NODES, LABELS =
부품 의 라인 수는 어떻게 알 수 있습니까?
이 경우 숫자는 6
입니다.
GLOBAL DOF SET NODES, LABELS =
줄 (strfind 사용?)과 끝 빈 줄 을 찾을 수 있다고 생각합니다 . 하지만 어떻게?
실제로 strcmp 또는 strfind 또는 regexp를 사용하여 문자열을 비교할 수 있습니다. 핵심은 비교할 문자열을 얻는 것입니다. 이것은 fgetl 함수를 사용하여 한 줄씩 파일을 읽어서 수행됩니다 .
# Open your file and assign it's handel to fileID:
fileID = fopen('yourFile.txt','r');
# Let's use the strcmp method and define your strings you test with:
yourFirstLine = ' GLOBAL DOF SET NODES, LABELS =';
# Your second line, in this case and empty line:
yourSecondLine = '';
# Use the variable flag to signal that you found your first line:
flag = 0;
iLine = 0;
while ~feof(fileID)
currentLine = fgetl(fileID);
# Check if header line matches with the current line and store in iMatchOne:
if strcmp(currentLine,yourFirstLine)
iMatchOne = iLine;
flag = 1;
end
# If you already found your first line it's time to start testing for the second line.
if flag == 1
if strcmp(currentLine,yourSecondLine)
iMatchTwo = iLine;
# You could decide here to break, because more matches with '' will be found!
end
end
iLine = iLine + 1;
end
도움이 되었기를 바랍니다!
필수 사항이 아님 : (첫 번째 검사에 if 플래그 == 0을 추가 할 수도 있습니다. 다른 방법은 첫 번째 줄을 찾으면 while 루프를 끊고 새 while 루프에서 다시 시작하여 테스트를 수행하는 것입니다. 두 번째 줄, fgetl이 검색하는 라이너 번호는 현재 줄 위치를 닫거나 다시 열거 나 수동으로 재설정 할 때까지 재설정되지 않습니다.)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다