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 日

4 投票

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!
Callum
Callum 2017 年 11 月 29 日
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.

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by