How to find multiple table column numbers by column names?
조회 수: 3 (최근 30일)
이전 댓글 표시
Using the following code, can get the column number of 'rk_mill_tonnage' in the table.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/660220/image.png)
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?
댓글 수: 0
채택된 답변
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');
댓글 수: 0
추가 답변 (1개)
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 Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!