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

1 vue (au cours des 30 derniers jours)
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 commentaires
Mathieu NOE
Mathieu NOE le 9 Déc 2021
hello
it could be helpful if you share the input data as well (var_nm.Properties.VariableNames)
Chao Zhang
Chao Zhang le 9 Déc 2021
'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'

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 9 Déc 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by