importing .txt file using textscan
5 次查看(过去 30 天)
显示 更早的评论
Good Afternoon, I am trying to import data from a text file in order to plot, and need help writing a scipt.
the text file has text as well as numerical data within it so the load function wont work.
I don't fully understand how the textscan function works, my text data has the first 4 rows with just text, and then the columnheaders in each column, (row 5). Every row past this is just space separated numerical data.
How would I write the command out as to import the data into a usable format to plot with? The data is seprated by spaces (no commas)
0 个评论
采纳的回答
Walter Roberson
2012-4-4
fid = fopen('YourFile.txt','rt');
datacell = textscan(fid, '%f%f%f', 'HeaderLines',5);
fclose(fid);
After that, datacell{1} is a vector containing the first column, datacell{2} is a vector containing the second column, datacell{3} is a vector containing the third column.
更多回答(1 个)
另请参阅
类别
在 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!