필터 지우기
필터 지우기

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