也许这个问题很奇怪,但无论如何.... 如何读取变量的值(字符串或数字)number_of_plots或color? (我想用变量/排列图选项来解决这个问题)Matlab:如何读取变量的值(字符串或数字)?
我的代码:
diagramoptions = [];
wholecontent = fileread('aaa.txt')
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens')
for section = sections
switch(strtrim(section{1}{1}))
case 'Diagram Options' %Diagram Options -> siehe meine Gliederung im .txt file
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
openvar diagramoptions
我输入 “aaa.txt”:
******************* Diagram Options****************
number_of_plots=4
header=Number of cycles
color=red
xlabel= RPM
ylabel= degree
好的,谢谢。有用。但在我看来有点复杂....必须有一个简单的方法......如果你打开“openvar图表选项”,你会发现第一列的名称为Key,第二列的名称为Value。所以我认为你必须问“哪个值有关键”number_of_plots“,但我不知道该怎么做...... – Lutz
你的问题是解决它..而我不明白为什么它很复杂?它基本上2如果语句清楚地读到了什么..但它肯定是比我自己的应用程序中写的更多的代码行(我在年龄中没有使用过Matlab) – Algar