How I can detection column indexes of string 'rk_accept_metaln' (n=1,2,3,4....)

1 次查看(过去 30 天)
I want to use the folloing code to automatic detection column indexes of 'rk_accept_metaln'(n=1,2,3,4,...n)
For example, run the following code, if the num=1, then the column index of rk_accept_metal1' is 9 (i.e. col_ind=9)
Then, the num >1, like num=2, we should get the column indexes of r1 and r2 (i.e col_ind=[9,11]) if running the code
%Determine the column index of variable names
match_var1 = str2double(regexp(var_nm.Properties.VariableNames, '(?=rk_accept_)+((?<=^metal)\d)$','once','match'));
ind_rmg = find(match_var1 <= num1);
But i cannot get anything if i use this code, i think the point is '(?=rk_accept_)+((?<=^metal)\d)$', but i have no idea how to fix it
Thanks in advance for help!
  2 个评论
Mathieu NOE
Mathieu NOE 2021-12-9
hello
it could be helpful if you share the input data as well (var_nm.Properties.VariableNames)
Chao Zhang
Chao Zhang 2021-12-9
'X' 'Y' 'Z' 'X_size' 'Y_size' 'Z_size' 'volume' 'block_tonnage' 'rk_accept_grade1' 'rk_accept_metal1' 'rk_rejected_grade1' 'rk_rejected_metal1' 'rk_accept_grade2' 'rk_accept_metal2' 'rk_rejected_grade2' 'rk_rejected_metal2' 'rk_accept_tonnage' 'rk_rejected_tonnage' 'sg' 'volume_factor'

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2021-12-9
C = {'X','Y','Z','X_size','Y_size','Z_size','volume','block_tonnage','rk_accept_grade1','rk_accept_metal1','rk_rejected_grade1','rk_rejected_metal1','rk_accept_grade2','rk_accept_metal2','rk_rejected_grade2','rk_rejected_metal2','rk_accept_tonnage','rk_rejected_tonnage','sg','volume_factor'};
N = str2double(regexp(C, '(?<=rk_accept_metal)\d+$','once','match'))
N = 1×20
NaN NaN NaN NaN NaN NaN NaN NaN NaN 1 NaN NaN NaN 2 NaN NaN NaN NaN NaN NaN

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by