Read numbers from text files into Matlab

조회 수: 2 (최근 30일)
SAMUEL AYINDE
SAMUEL AYINDE 2017년 5월 19일
편집: Yuebin Zhou 2017년 5월 23일
Please, check the attached files. I want to add U1 from squarecantout to the second column in squarecantinp; U2 from squarecantout to the third column in squarecantinp; and U3 from squarecantout to the fourth column in squarecantinp. Please, note that now there are 121 total nodes, the code will also be used for some other total number of nodes.
This is what I mean: squarecantinp:
*NODE
1, 110.0 , 40.0 , 0.0
2, 110.0 , 42.0 , 0.0
3, 110.0 , 44.0 , 0.0
4, 110.0 , 46.0 , 0.0
5, 110.0 , 48.0 , 0.0
Sqaurecantout:
THE FOLLOWING TABLE IS PRINTED FOR ALL NODES
NODE FOOT- COOR1 COOR2 COOR3 U1 U2 U3 UR1 UR2 UR3
NOTE
1 1.1000000E+02 4.0000000E+01 0.0000000E+00 -9.5834174E-04 -1.8739473E-03 0.0000000E+00 0.0000000E+00 0.0000000E+00 -5.3880304E-04
2 1.1000000E+02 4.2000000E+01 0.0000000E+00 -1.2443815E-04 -1.0014961E-03 0.0000000E+00 0.0000000E+00 0.0000000E+00 -7.7035733E-05
3 1.1000000E+02 4.4000000E+01 0.0000000E+00 -2.8663909E-04 -1.0340261E-03 0.0000000E+00 0.0000000E+00 0.0000000E+00 -7.0132205E-05
4 1.1000000E+02 4.6000000E+01 0.0000000E+00 -3.7078082E-05 -8.6013472E-04 0.0000000E+00 0.0000000E+00 0.0000000E+00 -4.0429371E-05
5 1.1000000E+02 4.8000000E+01 0.0000000E+00 -7.3307770E-05 -8.2926926E-04 0.0000000E+00 0.0000000E+00 0.0000000E+00 -3.3505471E-05
Finally, in squarecantinp: I want to have have the result of the following:
*NODE
1, second column -U1 third column-U2 forth column -U3
2, second column -U1 third column-U2 forth column -U3
3, second column -U1 third column-U2 forth column -U3

답변 (1개)

Yuebin Zhou
Yuebin Zhou 2017년 5월 23일
편집: Yuebin Zhou 2017년 5월 23일
"textscan" could be useful in this case.
https://www.mathworks.com/help/matlab/ref/textscan.html
There are more functions about reading files.
https://www.mathworks.com/help/matlab/text-files.html

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by