How to read a .txt file?
조회 수: 13 (최근 30일)
이전 댓글 표시
I have a .txt file with 1000000 rows and 14 columns. I want to read in Matlab but I'm not getting to do it. I'm using these commands:
fileID = fopen('data.txt','r');
formatSpec = '%.4f'
A = fscanf(fileID,formatSpec)
The file content an array like this (with 1000000 rows and 14 columns):
-34.7963 -7.1508 26.9324 26.8133 93.7783 41.8818 113.8538 65.2745 48.8024 30.8768 55.4924 14.6723 6.7068 22.6966
-34.7963 -7.1553 25.5952 27.5086 86.3124 40.4655 109.2303 64.8125 45.9477 29.5626 53.7228 15.9957 5.3562 18.0334
Can you help me? Thanks!
댓글 수: 0
채택된 답변
Walter Roberson
2022년 1월 28일
A = readmatrix('data.txt');
Unless you have a sufficiently old MATLAB.
With that file format you could also just
A = load('data.txt');
which might be faster.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!