Getting data from specific columns in a table
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello:
I have table_1 and say it has 6 columns. I would to love to have a code that will enable me to get data from a specific column(s) by using the column number or numbers.So lets say I want data from columns 2 and 3, the code should enable me to enter 2 and 3 and then it will search the table and return the data associated with the specified column(s).
Thank you guys.
採用された回答
You get data from a table by using the dot-notation. Therefore use the name of the column. If your columns are named 1...6 use
table_new = table_old.2
to get data from the column named '2'.
Here is an example:
A = table(['a'; 'b'; 'c'],[1; 2; 3],'VariableNames',{'x', 'y'})
If you use:
A.y
you get an array containing all values of the column named 'y'.
Best regards
Stephan
9 件のコメント
Curious Mind
2018 年 8 月 21 日
This is what I got when I executed it. table_new = table_old.2 | Error: Unexpected MATLAB expression.
What is the result if you type:
whos your_table_name
To avoid missunderstanding: table_old is a placeholder since i do not know the name of your table ans the names of their columns.
If i assume that your table is named table_1 and the true name of the columns is 1...6:
result(:,1) = table_1.2;
result(:,2) = table_1.3;
Will give you the columns 2 and 3 from your table in a new array called result.
Curious Mind
2018 年 8 月 21 日
Nothing at all. My table is named Tabel_A. so i used Table_new = Table_A.2 so i can get the data from column 2 but it doesnt work. I'm new to matlab and I dont know if what i have is even a table ( it shows 100x500 double)
this is what i get:
Name Size Bytes Class Attributes
table_old 1x491 3928 double
Name Size Bytes Class Attributes
Table_A 101x3423 2765784 double
You dont use a table. This is an array. If class is not table you do not deal with a table.
Curious Mind
2018 年 8 月 21 日
Oh sorry for the confusion. It's my fault. I'm new to this so i used the terms wrongly
So you use:
B = Table_A(:,2:3)
to get what you want.
Curious Mind
2018 年 8 月 21 日
Thank you very much. It works
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Tables についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
