Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Mathieu NOE
Mathieu NOE am 9 Dez. 2021
hello
it could be helpful if you share the input data as well (var_nm.Properties.VariableNames)
Chao Zhang
Chao Zhang am 9 Dez. 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'

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 9 Dez. 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

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by