I want load my text file to read.
I want [nodes, elem, C, A, bcs, loads] as an output form and the input file is below.
filename = uigetfile('*.txt','Select the inpuf file');
[nodes,elems,C,A,bcs,loads] = gettrussdata2D(filename);
function[nodes,elems,C,A,bcs,loads] = gettrussdata2D(filename)
..
..
end
<Input text file>
Nodes: (x,y)
0.0 0.0
2.0 0.0
2.0 2.0
0.0 0.0
Elements: (Node1 Node2),E,A
1 2 2e11 1e-5
1 3 2e11 1e-5
1 4 2e11 1e-5
4 3 2e11 1e-5
4 2 2e11 1e-5
2 3 2e11 1e-5
BCs (Node_number dof specified_disp)
2 1 0
2 2 0
3 1 0
3 2 0
Nodal loads (Node_number dof load)
4 1 2e4
4 2 -4e4

 採用された回答

Walter Roberson
Walter Roberson 2019 年 6 月 5 日

1 投票

S = fileread(filename);
np = regexp(S, '^Nodes:', 'once', 'lineanchors');
ep = regexp(S, '^Elements:', 'once', 'lineanchors');
bcp = regexp(S, '^BCs', 'once', 'lineanchors');
nlp = regexp(S, '^Nodal loads', 'once', 'lineanchors');
nodes = cell2mat( textscan(S(np : ep-1), '%f %f', 'HeaderLines', 1) );
elements = cell2mat( textscan(S(ep:bcp-1), '%f %f %f %f', 'HeaderLines', 1));
bcs = cell2mat( textscan(S(bcp:nlp-1), '%f %f %f', 'HeaderLines', 1));
nls = cell2mat( textscan(S(nlp:end), '%f %f %f', 'HeaderLines', 1));

3 件のコメント

Jisu Yang
Jisu Yang 2019 年 6 月 5 日
What if I want to distinguish (Node_number, dof, specified disp) in nls, I mean 'Nodal loads' parts ? It is becaus I have to call Node_number in code.
Walter Roberson
Walter Roberson 2019 年 6 月 5 日
Node_number = nls(:,1);
dof = nls(:,2);
specified_disp = nls(:,3);
Jisu Yang
Jisu Yang 2019 年 6 月 5 日
Thanks a lot :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFilename Construction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by