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

1 回表示 (過去 30 日間)
Chao Zhang
Chao Zhang 2021 年 6 月 12 日
コメント済み: Chao Zhang 2021 年 6 月 12 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by