Read values from a variable

4 ビュー (過去 30 日間)
Philipp Mueller
Philipp Mueller 2017 年 1 月 10 日
コメント済み: Philipp Mueller 2017 年 1 月 10 日
Hi,
I want to read from my input (test_input.txt - File) some specific data. I need this data for calculations and settings. Everything works except the input variable wsectionstart from my test_input.txt Because i have more than one value after = .... In my whole code i get the output message wsectionstart = NaN -> https://de.mathworks.com/help/stats/nanmean.html My question is how can i read this variable without any error messages. So i can read every single value from wsectionstart like wsectionstart(1) or wsectionstart(2). How should i modify my code? The following code is just a small reduced part from my whole code ->
diagramoptions = [];
wholecontent = fileread('test.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')));%does not work because i have an array of values

採用された回答

Guillaume
Guillaume 2017 年 1 月 10 日
wsectionstart = str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionstart')));
should solve the problem?
  4 件のコメント
Guillaume
Guillaume 2017 年 1 月 10 日
OK, after testing:
wsectionstart = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
Philipp Mueller
Philipp Mueller 2017 年 1 月 10 日
It works well. Thank you so much. I really appreciate it! I can just say thank you ...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by