Read text file with string
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmed Anas
el 4 de Mzo. de 2020
Respondida: Guillaume
el 4 de Mzo. de 2020
Hi all,
I have to read the file (inserted in attachment) and only need the numeric portion as a matrix(array). The extension of file is .TXK .
Thanks in advance
0 comentarios
Respuesta aceptada
Turlough Hughes
el 4 de Mzo. de 2020
Editada: Turlough Hughes
el 4 de Mzo. de 2020
You could use the readmatrix function as follows:
filename = 'My2.TXK'
opts = detectImportOptions(filename,'FileType','text')
data = readmatrix(filename,opts)
the .TXK extension is not recognised by readmatrix which is why I specified the FileType as text in the import options.
You could optionally read in as a table:
T = readtable(filename,opts)
If you want to get the variable names automatically, for example if you have a number of similar data files, I would need to see what the first line of text looks like generally across the files.
4 comentarios
Más respuestas (1)
Guillaume
el 4 de Mzo. de 2020
Should work in R2016a:
filename = 'My2.TXK'; %using full path would be better
[fid, errmsg] = fopen(filename, 'rt');
assert(fid > 0, 'Failed to open "%s" due to error: %s', filename, errmsg);
data = cell2mat(textscan(fid, '%f%f%f', 'Delimiter', {'\t', ' '}, 'MultipleDelimsAsOne', true, 'HeaderLines', 1));
fclose(fid);
0 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!