How to find table column number by column name?

155 ビュー (過去 30 日間)
Joyjit Chatterjee
Joyjit Chatterjee 2018 年 12 月 11 日
コメント済み: Sean de Wolski 2018 年 12 月 11 日
I have a Table in MATLAB, suppose the table is A of dimensions 21392x1970. There are 1970 columns in table A, as evident. There is a column named "Temperature" and I would like to find out the column number of that column eg. between 1-1970 which value in my table. How can I find the column number of a MATLAB table column by specifying the name of the column? Any help in this regard would be highly appreciated. Cheers and Thanks!

採用された回答

Sean de Wolski
Sean de Wolski 2018 年 12 月 11 日
tidx = find(string(T.Properties.VariableNames) == "Temperature")
  2 件のコメント
Stephen23
Stephen23 2018 年 12 月 11 日
Would
find(strcmp(T.Properties.VariableNames,'Temperature'))
also work?
Sean de Wolski
Sean de Wolski 2018 年 12 月 11 日
Yeah, strcmp, and ismember would both work. I've been using the datatype string strings for pretty much everything so doing an equal (or ismember) is more natural.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 12 月 11 日
varnames = A.Properties.VariableNames;
[tf, column_number] = ismember('Temperature', varnames);
if ~tf
error('Temperature is not one of the table variables')
end

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by