私の入力ファイル(test_input.txt
)から特定のデータを読みたいです。計算と設定にこのデータが必要です。Matlab:変数から値を読み込む?
私のtest_input.txt
ファイルの入力変数wsectionstart
以外はすべて動作します。
wsectionstart = NaN
私の質問は、私はすべてのエラーメッセージなしでこの変数を読むことができる方法です:私は、全体のコードを実行すると
は、私は、出力メッセージが表示されます。だから私はwsectionstart
wsectionstart(1)
またはwsectionstart(2)
のようなすべての単一の値を読むことができます。コードをどのように変更すればよいですか?
次のコードは、私の全体のコードからほんの減少一部です:
diagramoptions = [];
wholecontent = fileread('test_input.txt');
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens');
for section = sections
switch(strtrim(section{1}{1}))
case 'Diagram Options'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens'); %\n -> new line; \r carriage return
diagramoptions = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'});
otherwise
warning('Unknown section: %s', section{1}{1}),
end
end
linewidth=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'linewidth'))); %works
xlabel=diagramoptions.Value(strcmp(diagramoptions.Key, 'xlabel')); %works
wsectionstart=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionstart')))
そして、これはここに私のtest_input.txt
ファイル
******************* Diagram Options****************
linewidth=12
wsectionstart=1000000 3000000
xlabel= Capture
期待される出力は何ですか?テキストファイルのどの値を保存したいのですか?どのように保存しますか?あなたのコードからこれを判断することは非常に困難です。 – rayryeng
変数 "wsectionstart"には2つの値があります - > test.txtを参照してください。私は、最初の値と2番目の値を読み取り、配列に格納したい。 – Lutz
あなたのファイルは 'test_input.txt'と呼ばれていますが、あなたのコードでは' test.txt'として読み込みます...それは? – Wolfie