テキストファイル(.txt形式)からの数値のみの読み取り方法について。
Show older comments
K.txtのファイルの内容が、例えば以下のようなものです。
----------
K # states: 5 state set: 0 ... 4 initial state: 0
marker states:
0
vocal states: none
# transitions: 6
transitions:
[ 0, 11, 1] [ 1, 12, 0] [ 1, 21, 2] [ 2, 22, 1]
[ 2, 31, 3] [ 3, 32, 4]
----------
states,state set, initial state, transitionsは整数一文字ですが、
marker statesは複数になる場合もあります。
このテキストファイルから数値のみを読み取り、それぞれ格納したいのですが、(例:transitions = [0, 11, 1;1, 12, 0...]、marker = [0]など)
どのようにすればいいでしょうか。
とりあえず全部の数値データのみを読み取ろうと考え、
----------
fileID = fopen('K.txt', 'r');
formatSpec = ('%d');
A = fscanf(fileID, formatSpec);
----------
とすると、A = []と空行列になります。
どのようにすれば数値のみを取り出すことができるでしょうか。
できることならばそれぞれのデータを別で格納したいです。
Answers (0)
Categories
Find more on テキスト ファイル in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!