How to find multiple table column numbers by column names?

6 ビュー (過去 30 日間)
Chao Zhang
Chao Zhang 2021 年 6 月 21 日
コメント済み: Chao Zhang 2021 年 6 月 22 日
Using the following code, can get the column number of 'rk_mill_tonnage' in the table.
col_ind_rmt = find(string(G_Value.Properties.VariableNames) == "rk_mill_tonnage");
However, the 'rk_mill_tonnage' might be differnet from table to table, for example, 'ore_mill_tonnage' in another table
col_ind_rmt = find(string(G_Value.Properties.VariableNames) == "rk_mill_tonnage" || 'ore_mill_tonnage');
The above code is wrong, as the '||' is using in scalar.Therefore, is there any other ways to get the column number among the multiple names?

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 6 月 21 日
編集済み: Scott MacKenzie 2021 年 6 月 21 日
col_ind_rmt = find(string(G_Value.Properties.VariableNames) == "rk_mill_tonnage" | ...
string(G_Value.Properties.VariableNames) == 'ore_mill_tonnage');

その他の回答 (1 件)

dpb
dpb 2021 年 6 月 21 日
編集済み: dpb 2021 年 6 月 21 日
col_ind_rmt = find(string(G_Value.Properties.VariableNames) == "rk_mill_tonnage" || 'ore_mill_tonnage');
Just replace "||" with "|" would make the above work but simpler coding would be
col_ind_rmt=find(contains(G_Value.Properties.VariableNames,'_mill_tonnage'));
that will return either of the above but not return 'mill_tonnage' if there were a name without a prefix and underscore.
Or, of course, you can get as sophisticated as desired/needed by using regular expressions

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by