Unable to read from text file

조회 수: 2 (최근 30일)
Emmanuel
Emmanuel 2017년 3월 15일
댓글: Star Strider 2017년 3월 15일
My textfile(sample pasted below) contains sequence of numbers.
Below is my snippet of code to read it:
jointAngle = strcat('/mnt/seagate/dataset/RobotDemo/joint_angles/',jointAngles(1).name)
fileID = fopen(jointAngle,'r')
formatSpec = '%f';
A = fscanf(fileID, formatSpec)
My output:
jointAngle= '/mnt/seagate/dataset/RobotDemo/joint_angles/1489512207.73.txt'
A = []
1) Why is my file not being read? 2) How can I convert this text content into arrays to plot a graph?
Sample.txt
-3.01772370152
-1.56849535382
1.21606326821
-0.371606845441
0.495475793921
-2.06473813813
1.36600989005
-0.0452524331909
-0.608606876898
0.0
-0.461344721429
-0.995170035004
0.704480676031
-12.5659871048
1.59840797915
1.80894684205
1.25556327345
Thanks!
  댓글 수: 2
KSSV
KSSV 2017년 3월 15일
What error you get? You have to check your path...are you giving the path correctly?
Star Strider
Star Strider 2017년 3월 15일
Where in your code did you put:
A = []
If you put it after you read the file, you deleted everything in ‘A’.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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