txtファイルからス​ペース区切りで改行し​ながら、周期的にイン​ポートする方法を教え​てください。

10 views (last 30 days)
K_S_
K_S_ on 13 Sep 2022
Commented: K_S_ on 14 Sep 2022
現在、添付したsample.txtのようなファイルがあります。
これを、下記の形でtableにインポートしたいです。
方法をご教示願います。
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
00000009
00000010

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 13 Sep 2022
readtable関数を用います。
一つおきに入っている"00000000"は上位の桁とみなすのでしょうか? 下記は単に"00000000"を読み飛ばす例です。
tbl = readtable('sample.txt', ... % 読み込むファイル名
'TextType', 'string', ... % インポートされるテキストデータの型('char'|'string')
'ReadVariableNames', false, ... % 最初の行を変数名として読み取るか否か
'Delimiter',' ', ... % フィールドの区切り記号
'NumHeaderLines',4, ... % ヘッダーの行数
'Format','%s %*s') % 列の形式。%*s⇒%sに変えると"00000000"も読み込む
tbl = 10×1 table
Var1 __________ "00000001" "00000002" "00000003" "00000004" "00000005" "00000006" "00000007" "00000008" "00000009" "00000010"
  1 Comment
K_S_
K_S_ on 14 Sep 2022
"00000000"は読み飛ばすことを意図していました。
意図を汲んでご回答いただきありがとうございました。

Sign in to comment.

More Answers (0)

Categories

Find more on データのインポートと解析 in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!