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 Center および File ExchangeWorkspace 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