Getting data from specific columns in a table
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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.
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.
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.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
