How to read .txt file in matlab (comma delimiter)

18 Ansichten (letzte 30 Tage)
Samantha Chong
Samantha Chong am 5 Nov. 2015
Beantwortet: Walter Roberson am 5 Nov. 2015
Hi guys, I would like to read all the data (including the header) from this .txt file, I could only read the numbers using dlmread, please assist me on this:
Adjusted depth,temp,trans
1,22.5,122.3
3,22.6,111.5

Antworten (1)

Walter Roberson
Walter Roberson am 5 Nov. 2015
fid = fopen('YourFile.txt', 'rt');
tline = fgetl(fid);
headers = strsplit(tline, ','); %a cell array of strings
datacell = textscan(fid, '%f%f%f', 'Delimiter',',', 'CollectOutput', 1);
fclose(fid);
datavalues = datacell{1}; %as a numeric array

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by