Extract nodes and elements from abaqus input file to matlab

Hello,
I have an abaqus input file with the following structure:
Now I want to extract the nodes and elements to matlab in order to do computations there. I have two problems:
  • The nodes of each elements are written in 2 lines. How can I change this to one line without joining each line individually?
  • Whats in general the easiest and fastest way to read this out?
Thanks

 채택된 답변

KSSV
KSSV 2016년 10월 14일
clc; clear all ;
fname = 'example.txt' ;
fid = fopen(fname,'rt') ;
S = textscan(fid,'%s','Delimiter','\n');
S = S{1} ;
%%Get the line number of mises
idxS = strfind(S, 'Node');
idx1 = find(not(cellfun('isempty', idxS)));
idxS = strfind(S, 'Element');
idx2 = find(not(cellfun('isempty', idxS)));
idxS = strfind(S, 'End');
idx3 = find(not(cellfun('isempty', idxS)));
% pick nodes
nodes = S(idx1+1:idx2-1) ;
nodes = cell2mat(cellfun(@str2num,nodes,'UniformOutput',false))
% pick elements
elements = S(idx2+1:idx3(1)-1) ;
count = 0 ;
ele = cell(length(elements)/2,1) ;
for i = 1:2:length(elements)
count = count+1 ;
ele{count,1} = [elements{i} elements{i+1}];
end
ele = cell2mat(cellfun(@str2num,ele,'UniformOutput',false))

댓글 수: 2

Daniel Heilmann
Daniel Heilmann 2016년 10월 14일
편집: Daniel Heilmann 2016년 10월 14일
Thank you very much! I testet the code and it is exactly what I was looking for!
A way to speed this up is to use the first half of the code (up to idx3), then use dlmread with the idx values as row offsets to read in numerical data. It's a bit ugly, but it's much faster (especially if you have millions of nodes/elements). Just put (after line 12)
nodes = dlmread(fname,',',[idx1,0,idx2-2,2]);
elements = dlmread(fname,',',[idx2,0,idx3(1)-2,3]);
Not sure this gives exactly the same output (I was too impatient to let the original run out) but it gets you node and element info.

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

추가 답변 (2개)

KSSV
KSSV 2016년 10월 14일
편집: KSSV 2016년 10월 14일

0 개 추천

doc textscan

0 개 추천

Dear KSSV,
ele = cell2mat(cellfun(@str2num,elements,'UniformOutput',false)); is this correct without loop?
I didnt understand why you used loop at the end.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by