Extract nodes and elements from abaqus input file to matlab
21 views (last 30 days)
Show older comments
Daniel Heilmann
on 14 Oct 2016
Answered: Praveen Venkatesh Sethumadhavan Vasan
on 2 Jul 2019
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
0 Comments
Accepted Answer
KSSV
on 14 Oct 2016
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 Comments
Callum
on 29 Nov 2017
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.
More Answers (2)
Praveen Venkatesh Sethumadhavan Vasan
on 2 Jul 2019
Dear KSSV,
ele = cell2mat(cellfun(@str2num,elements,'UniformOutput',false)); is this correct without loop?
I didnt understand why you used loop at the end.
0 Comments
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!