Reading a text file into an array
조회 수: 15 (최근 30일)
이전 댓글 표시
I want to read a text file called test that contains integers into an array. I keep recieving an error. How do I read a text file into an array?

% This is the code
fileID = fopen('Test.txt','r');
formatSpec = '%d %f';
sizeA = [2 Inf];
A = fscanf(fileID,formatSpec,sizeA);
fclose(fileID);
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 11월 7일
This error can occur if MATLAB cannot fine the file Test.txt. Make sure that the file is placed in the current folder or specify the complete path to the file.
댓글 수: 0
추가 답변 (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!