Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Stephen23
Stephen23 am 12 Jun. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by