matlab reads the.geo file

9 次查看(过去 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 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by