Matlab: Select a variable name and find the corresponding value
Show older comments
Can somebody explain me how i get some specific values after the = sign? The input File is a .subvar file format. 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.
I need for example two specific values (after the = sign): The value of $_Wk1_lr_m and $_Wk1_voll_m
Result: 15601 and 33690
!file.version=1.543!
! Test
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)

Accepted Answer
More Answers (1)
Stephen23
on 16 Apr 2020
One simple regular expression:
str = fileread('test.subvar');
rgx = 'Wk1_(lr|voll)_m\D+(\d+)';
tkn = regexp(str,rgx,'tokens');
tkn = vertcat(tkn{:})
Giving:
tkn =
'lr' '15601'
'voll' '33690'
Which of course you can easily convert to numeric:
>> vec = str2double(tkn(:,2))
vec =
15601
33690
Categories
Find more on Programming 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!