필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
I want to use the folloing code to automatic detection column indexes of 'rn_mill_tonnage'(n=1,2,3,4,...n)
For example, run the following code, if the num=1, then the column index of r1_mill_tonnage' is 9 (i.e. col_ind_rn=9)
However, then the num >1, like num=2, we should get the column indexes of r1 and r2 (i.e col_ind_rn=[9,11]) if running the code, but the point is I can only get the column index of r2 (i.e. col_ind_rn=11)
Therefore, how to fix the code and get multiple column indexes of ‘rn_mill_tonnage' when num>1?
Thanks in advance for help!
%% 5.Automatic detection column indexes of 'rn_mill_tonnage'(n=1,2,3,4,...n)
STR = cell(1,num);%create cell to store multiplr strings
counter_str = 1;
for k = 1 : num
STR{k} = sprintf('r%d_mill_tonnage',k);
col_ind_rn = find(string(G_Value.Properties...
.VariableNames(1: size(G_Value,2))) == STR{k});
end

채택된 답변

Stephen23
Stephen23 2021년 6월 12일
C = {'X','Y','Z','size(X)','size(Y)','size(Z)','volume','r1_cu_mill_grade','r1_mill_tonnage','r2_cu_mill_grade','r2_mill_tonnage'};
V = str2double(regexp(C,'(?<=^r)\d+(?=_mill_tonnage$)','once','match'))
V = 1×11
NaN NaN NaN NaN NaN NaN NaN NaN 1 NaN 2
find(V<=1)
ans = 9
find(V<=2)
ans = 1×2
9 11

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by