Read data from a .txt file with two columns

146 visualizzazioni (ultimi 30 giorni)
Lillian Lau
Lillian Lau il 30 Lug 2018
Commentato: Lillian Lau il 30 Lug 2018
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

Risposte (1)

Paolo
Paolo il 30 Lug 2018
Modificato: Paolo il 30 Lug 2018
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)

Categorie

Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by