How to import one column from txt file
14 ビュー (過去 30 日間)
古いコメントを表示
Hi
I need to import one column from .txt file which contains only numbers like 1.54 1.28 ...
Which function does that?
Thanks
0 件のコメント
回答 (4 件)
Jos (10584)
2014 年 3 月 7 日
Take a look at at one of the import functions (textscan, load, etc.)
The easiest way is to import all the columns and then only keep the one you want to keep. For instance:
A = load ...
A = A(:,IndexOfColumnToKeep) ;
0 件のコメント
Image Analyst
2014 年 3 月 7 日
You can use csvread if it's in csv format
M = csvread(filename,row,col)
Or use dlmread, importdata, textscan, fgetl, etc. depending on the format of the text file.
1 件のコメント
Image Analyst
2014 年 3 月 8 日
That file has such a big variety of formats that I'd probably just use allwords and fgetl(). Then build up a cell array of the words in a loop and then call xlswrite. In pseudocode
fid = fopen('S1P1.txt', 'r');
tline = fgetl(fid);
lineCounter = 1;
while ischar(tline)
disp(tline)
tline = fgetl(fid);
% Separate the line into separate words.
theWords = allwords(tline);
% Put the words into a cell array.
for k = 1 : length(theWords)
ca{lineCounter, k} = theWords{k};
end
end
xlswrite('text.xlsx', ca);
fclose(fid);
That's untested code just off the top of my head and it may need debugging (which I hope you know how to do).
Dominika
2014 年 3 月 8 日
1 件のコメント
per isakson
2014 年 3 月 8 日
編集済み: per isakson
2014 年 3 月 8 日
- Which lines are part of the file?
- Why not using Excel?
参考
カテゴリ
Help Center および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!