필터 지우기
필터 지우기

Read data from a .txt file with two columns

조회 수: 62 (최근 30일)
Lillian Lau
Lillian Lau 2018년 7월 30일
댓글: Lillian Lau 2018년 7월 30일
Hello, I have a .txt file with two jagged columns (example shown as code). How do I read these two columns into two different arrays? I have tried the load() and xlsread(), but I usually end up with one .xlsx file with both columns squished into one .xlsx column. Would appreciate suggestions, and thank you in advance!
Example:
1.33 333.2
1.5678 7.211
1.9 1.2346

답변 (1개)

Paolo
Paolo 2018년 7월 30일
편집: Paolo 2018년 7월 30일
If you want a cell array you can use:
fileID = fopen('mytext.txt');
mydata = textscan(fileID,'%f%f','HeaderLines',1);
fclose(fileID);
If you prefer a table you can use:
t = readtable('mytext.txt','ReadVariableNames',false)
  댓글 수: 1
Lillian Lau
Lillian Lau 2018년 7월 30일
Would the table be stored as an Excel file?

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by