Read data couples from txt file

1 次查看(过去 30 天)
Sara Satanassi
Sara Satanassi 2017-11-17
回答: KL 2017-11-18
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

回答(1 个)

KL
KL 2017-11-18
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,

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by