フィルターのクリア

matlab reads the.geo file

6 ビュー (過去 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 Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by