Read data couples from txt file

1 visualización (últimos 30 días)
Sara Satanassi
Sara Satanassi el 17 de Nov. de 2017
Respondida: KL el 18 de Nov. de 2017
Hello everyboby I'm pretty new on Matlab and I've got a simple question: I have to read some data couples from text file as formatted:
"51361"\t"64400"\r "51361"'\t'"29911"\r . . . "64400"'\t'"29911"\r "64400"'\t'"1488"\r
My goal is to put this couples in two different arrays as shown:
s = [51361, 51361,..., 64400, 64400] t = [64400, 29911,..., 29911, 1488]
could someone help me with the code?
Thank you very much.
Sara

Respuestas (1)

KL
KL el 18 de Nov. de 2017
Does your file also have the double quotation mark and \t,\r as you have written? If not, something as simple as,
data = dlmread('filename.txt')
but output will be a matrix with two columns
if it's indeed including the double quotations and symbols and you just want to import the numbers, I'd recommend using textread
here you have to specify your format string and you can import them into separate variables,

Categorías

Más información sobre Workspace Variables and MAT 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!

Translated by