Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Chao Zhang
Chao Zhang le 12 Juin 2021
Commenté : Chao Zhang le 12 Juin 2021
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

Réponse acceptée

Stephen23
Stephen23 le 12 Juin 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing 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