Text files data extract

1 次查看(过去 30 天)
RAKESH KUMAR TOTA
RAKESH KUMAR TOTA 2021-1-26
Hi, Good morning
I have a very large text file. I here by attached for reference. I want to extraxt nodal displacements for 4961 nodes (1 displ 2 displ) in matrix forma in column wise. I have to extract mutliple times in a loop after every iteration so generalised code will be usefull. Any help would be appreciated. Thank you in advance.

回答(1 个)

Mathieu NOE
Mathieu NOE 2021-1-27
hello
this seems to work - even though there is maybe a better way to extract the numerical content from the table
I tried with other opts parameters, at the end I could make this to work
% node 1 Coord 2 Coord
% varNames = {'node','1 Coord','2 Coord'} ;
% varTypes = {'int32','double','double'} ;
datalines = [62 5613];
% opts = delimitedTextImportOptions('DataLines',datalines,'VariableNames',varNames ,'VariableTypes',varTypes);
opts = delimitedTextImportOptions('DataLines',datalines,'VariableTypes','char');
data_table = readtable('Onewfp.txt',opts);
[m,n] = size(data_table);
data_C = table2cell(data_table);
% code below could be replaced with correct opts for readtable ?
k = 0;
for ci = 1:m
C = strsplit(data_C{ci});
if ~isnan(str2num(C{1}))
k = k+1;
node_num(k,1) = str2num(C{1});
node1cor(k,1) = str2num(C{2});
node2cor(k,1) = str2num(C{3});
end
end

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by