How I can detection column indexes of string 'rn_mill_tonnage' (n=1,2,3,4....)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650845/image.png)
%% 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
0 commentaires
Réponse acceptée
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'))
find(V<=1)
find(V<=2)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!