How to read numbers from a txt file with numbers and text
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi there,
I have a txt file as the attached one.
I want to read only the numbers, in order to elaborate after the data into a matrix.
I'm trying with this code, but it does not work, cause it does not read the last columns.
path1='.../path1'
fid = fopen(path1);
data = textscan(fid,'%s%f%f%f%f%s%s%f%f','HeaderLines',1,'CollectOutput',1);
data = data{1,1};
fid = fclose(fid);
Can anyone help me? Thanks in advance
댓글 수: 0
채택된 답변
Image Analyst
2020년 5월 16일
Try readtable():
t = readtable('example.txt')
data = t(:, [1:4,11,12])
댓글 수: 2
Image Analyst
2020년 5월 17일
There is a table2array() function if you want to convert the table to a matrix.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!