Trouble loading in mixed data from txt file
5 次查看(过去 30 天)
显示 更早的评论
I'm trying to load in data from a text file. The first two rows are headers, following the headers the first two columns are date and time. The rest of the columns are floats.
data should have 11 columns, however, whos returns that size is only 1x3
fid = fopen('allunderway.txt', 'rt');
data = textscan(fid, '%{M/dd/yyyy}D %{HH:mm:ss}D %4.2f %2.4f %2.5f %2.4f %2.4f %2.2f %4.2f %3.1f %1.4f', 'HeaderLines', 2, 'CollectOutput', true);
fclose(fid);
whos data
date = data{1};
time = data{2};
wnd_td = data{10};
wnd_ts = data{11};

0 个评论
采纳的回答
Jeremy Hughes
2018-5-30
You're adding 'CollectOutput' which is concatenating all the numeric columns into one. If you remove that, you should get the number of columns you expect.
0 个评论
更多回答(1 个)
KSSV
2018-5-30
Try this:
fid = fopen('allunderway.txt', 'rt');
data = textscan(fid, '%{M/dd/yyyy}D %{HH:mm:ss}D %4.2f %2.4f %2.5f %2.4f %2.4f %2.2f %4.2f %3.1f %1.4f', 'HeaderLines', 2, 'Delimiter','\n', 'CollectOutput', true);
fclose(fid);
whos data
date = data{1};
time = data{2};
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!