Loading tab delimited .txt file with mix of strings and numeric data
Afficher commentaires plus anciens
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 commentaire
Azzi Abdelmalek
le 18 Fév 2014
Nothing is attached
Réponses (3)
per isakson
le 18 Fév 2014
Modifié(e) : per isakson
le 19 Fév 2014
.
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
le 18 Fév 2014
Modifié(e) : Azzi Abdelmalek
le 18 Fév 2014
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)
le 19 Fév 2014
You can skip the columns you do not want:
ValuesInCol2 = textread('Test28_Text_table.txt','%*s%f%*[^\n]','headerlines',1)
Catégories
En savoir plus sur Text Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!