Read numbers from text files into Matlab
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!