matlab reads the.geo file

조회 수: 10 (최근 30일)
Chenglin Li
Chenglin Li 2022년 12월 17일
답변: Voss 2022년 12월 18일
Hello!I have a.geo file, I want to extract all the information in it in matlab, all the Point, Line, Line Loop, Plane Surface, how can I extract the following data according to its string in matlab and convert it into a matrix。
  댓글 수: 2
KSSV
KSSV 2022년 12월 17일
What is attached .txt file? Where is .geo file?
Chenglin Li
Chenglin Li 2022년 12월 17일
The.geo file cannot be uploaded, but it has the same content as the.geo file.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 12월 18일
Here's one way:
fid = fopen('rec.txt','r');
text = fread(fid,'*char').';
fclose(fid);
data = regexp(text,'([\w ]+)\((\d+)\) = {(.+?)}','tokens');
data = vertcat(data{:});
data(:,1) = strrep(data(:,1),' ','_');
data(:,[2 3]) = cellfun(@str2num,data(:,[2 3]),'UniformOutput',false);
args = unique(data(:,1)).';
args(end+1,:) = {[]};
result = struct(args{:});
for ii = 1:size(data,1)
result.(data{ii,1}) = subsasgn( ...
result.(data{ii,1}), ...
substruct('()',{data{ii,2},':'}), ...
data{ii,3});
end
result
result = struct with fields:
Line: [13×2 double] Line_Loop: [6×4 double] Plane_Surface: [6×1 double] Point: [9×4 double] Surface_Loop: [1 2 4 5 3 6] Volume: 1
result.Point
ans = 9×4
0 0 0 1 0 0 0 1 4 0 0 1 4 4 0 1 0 4 0 1 0 0 1 1 4 0 1 1 4 4 1 1 0 4 1 1
result.Line
ans = 13×2
5 1 1 3 3 4 4 5 5 9 9 6 6 7 7 7 7 8 8 9
result.Line_Loop
ans = 6×4
10 6 7 9 10 -5 -4 -13 9 13 -3 -12 5 6 11 -1 7 12 -2 -11 4 1 2 3
result.Plane_Surface
ans = 6×1
1 2 3 4 5 6

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by