[英]Matlab: Select a variable name and find the corresponding value
Can somebody explain me how i get some specific values after the = sign?有人可以解释一下我如何在 = 符号后得到一些特定的值吗? The input File is a.subvar file format.输入文件是.subvar 文件格式。 I dont know how to jump in the right row and column to get the value.我不知道如何跳入正确的行和列来获取值。 Do you have a matlab tutorial link for such a problem.您是否有针对此类问题的 matlab 教程链接。
I need for example two specific values (after the = sign): The value of $_Wk1_lr_m and $_Wk1_voll_m例如,我需要两个特定值(在 = 符号之后): $_Wk1_lr_m 和 $_Wk1_voll_m 的值
!file.version=1.543!
! Testautomatisch
subvargroup.begin ($G_Wk1)
subvar( $_Wk1_lr_C_x, str = ' 0.019 ' )
subvar( $_Wk1_lr_m, str = ' 15601 ' ) ! [kg] lr
subvar( $_Wk1_lr_C_y, str = '-0.007 ' )
subvar( $_Wk1_lr_C_z, str = ' 1.644 ' )
subvar( $_Wk1_voll_m, str = ' 33690 ' ) ! [kg] voll
subvargroup.end ($G_Wk1)
What are the first steps to get the right row and the right column?获得正确的行和正确的列的第一步是什么? Thank you and stay at home:)谢谢你,待在家里:)
read the file line by line, match the line format and extract the values using regular expression regexp
逐行读取文件,匹配行格式并使用正则表达式regexp
提取值
fid=fopen('mydata.subvars','rt');
res=struct;
while(~feof(fid))
line=fgetl(fid);
if(regexp(line,'^\s*subvar\(','once'))
val=regexp(line,'\$_(\w+),\s*str\s*=\s*''\s*([0-9.-]+)\s*','tokens');
if(length([val{:}])==2)
res.(val{1}{1})=str2num(val{1}{2});
end
end
end
fclose(fid);
here is the result这是结果
>> res
res =
Wk1_lr_C_x: 0.0190
Wk1_lr_m: 15601
Wk1_lr_C_y: -0.0070
Wk1_lr_C_z: 1.6440
Wk1_voll_m: 33690
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.