필터 지우기
필터 지우기

Text files data extract

조회 수: 1 (최근 30일)
RAKESH KUMAR TOTA
RAKESH KUMAR TOTA 2021년 1월 26일
편집: RAKESH KUMAR TOTA 2021년 1월 27일
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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by