Getting data from specific columns in a table

18 visualizaciones (últimos 30 días)
Curious Mind
Curious Mind el 21 de Ag. de 2018
Comentada: Curious Mind el 21 de Ag. de 2018
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.

Respuesta aceptada

Stephan
Stephan el 21 de Ag. de 2018
Editada: Stephan el 21 de Ag. de 2018
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 comentarios
Stephan
Stephan el 21 de Ag. de 2018
Editada: Stephan el 21 de Ag. de 2018
So you use:
B = Table_A(:,2:3)
to get what you want.
Curious Mind
Curious Mind el 21 de Ag. de 2018
Thank you very much. It works

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by