clc; clear all ;
fname = 'example.txt' ;
fid = fopen(fname,'rt') ;
S = textscan(fid,'%s','Delimiter','\n');
S = S{1} ;
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)));
nodes = S(idx1+1:idx2-1) ;
nodes = cell2mat(cellfun(@str2num,nodes,'UniformOutput',false))
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))
Best Answer