matlab reads the.geo file

9 views (last 30 days)
Chenglin Li
Chenglin Li on 17 Dec 2022
Answered: Voss on 18 Dec 2022
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 Comments
KSSV
KSSV on 17 Dec 2022
What is attached .txt file? Where is .geo file?
Chenglin Li
Chenglin Li on 17 Dec 2022
The.geo file cannot be uploaded, but it has the same content as the.geo file.

Sign in to comment.

Accepted Answer

Voss
Voss on 18 Dec 2022
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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!