Borrar filtros
Borrar filtros

matlab reads the.geo file

6 visualizaciones (últimos 30 días)
Chenglin Li
Chenglin Li el 17 de Dic. de 2022
Respondida: Voss el 18 de Dic. de 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 comentarios
KSSV
KSSV el 17 de Dic. de 2022
What is attached .txt file? Where is .geo file?
Chenglin Li
Chenglin Li el 17 de Dic. de 2022
The.geo file cannot be uploaded, but it has the same content as the.geo file.

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 18 de Dic. de 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

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by