フィルターのクリア

getting a specific column from a table

527 ビュー (過去 30 日間)
Lorraine Williams
Lorraine Williams 2015 年 10 月 15 日
コメント済み: Walter Roberson 2015 年 10 月 16 日
Hi Guys So I have a table (T) that I created from a cvs file. It has column headers and I want to assign x = content so x column 1 and y = contents of col 2 (for example)
How do I do that?
It seems so silly to ask but I don't know the syntax.
x & y will be used in my linear regression model.
Thanks!!!

採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 15 日
x = T{1};
y = T{2};
  3 件のコメント
Peter Perkins
Peter Perkins 2015 年 10 月 16 日
If it's a table as in, you used readtable to read in a CSV file, that syntax won't work. Assuming your variable names in the table are X and Y, the simplest thing is just
x = T.X;
y = T.Y;
Alternatively,
x = T{:,'X'}; % or T{:,1}
y = T{:,'Y'}; % or T{:,2}
will work. There really is documentation for this, see for example, Accessing Data in a Table.
Walter Roberson
Walter Roberson 2015 年 10 月 16 日
Darn, I keep forgetting the : needed for extracting rows. ;(

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by