Loading tab delimited .txt file with mix of strings and numeric data
古いコメントを表示
I think I'm going crazy, but for the life of me I can't get this .txt file to load into Matlab. All I want is column 2 but I've tried the usual fopen,textscan,fclose route recommended in other posts. I've also tried functions like load, fileread, and some of the customised functions from other users. Nothing is working! I need some help please!
Sample data attached...
Any advice or solutions welcomed!
1 件のコメント
Azzi Abdelmalek
2014 年 2 月 18 日
Nothing is attached
回答 (3 件)
per isakson
2014 年 2 月 18 日
編集済み: per isakson
2014 年 2 月 19 日
.
Later
Try
fid = fopen( 'Test28_Text_table.txt', 'r', 'ieee-le', 'UCS-2' );
cac = textscan( fid, '%s%f%s%s', 'Delimiter', '\t', 'Headerlines', 1 );
fclose( fid );
>> cac{2}
ans =
3.4000
5.1000
80.6000
19.8000
100.4000
...
I get this warning, but it seems to work
Warning: The encoding 'UTF-16' is not supported.
See the documentation for FOPEN.
Notepad++ recognized the encoding of your file.
>> version
ans =
8.1.0.604 (R2013a)
Azzi Abdelmalek
2014 年 2 月 18 日
編集済み: Azzi Abdelmalek
2014 年 2 月 18 日
ii=fopen('file.txt')
s=textscan(ii,'%s')
fclose(ii)
out=regexp( cellstr(s{1}),'\d+(\.)?(\d+)?','match')
out=cellfun(@(x) str2num(x{1}),out(~cellfun(@isempty,out)))
Jos (10584)
2014 年 2 月 19 日
You can skip the columns you do not want:
ValuesInCol2 = textread('Test28_Text_table.txt','%*s%f%*[^\n]','headerlines',1)
カテゴリ
ヘルプ センター および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!