read from a text file and load it into a matrix in matlab [duplicate]

你离开我真会死。 提交于 2019-12-20 07:34:28

问题


I have a text file called coordinates.txt as following format:

0 0 0
-0.95 0.32 -0.02
-1.02 0.26 -0.96
-0.73 0.6 -0.52
-0.77 0.6 -0.71
-0.28 0 -0.95
-0.14 -0.16 0.13
-0.46 -1 -0.29
-1.14 -0.6 0.16

How could I load it in matlab with commands and save it in a matrix called X as following:

X=[0 0 0;
-0.95 0.32 -0.02;
-1.02 0.26 -0.96;
-0.73 0.6 -0.52;
-0.77 0.6 -0.71;
-0.28 0 -0.95;
-0.14 -0.16 0.13;
-0.46 -1 -0.29;
-1.14 -0.6 0.16;]

so each line in the text file will be saved as a row in matrix X.


回答1:


S = load('coordinates.txt', '-ascii');

Type 'help load' for more information.



来源:https://stackoverflow.com/questions/15756029/read-from-a-text-file-and-load-it-into-a-matrix-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!