Delete specific columns of a table

163 visualizaciones (últimos 30 días)
Zeynab Mousavikhamene
Zeynab Mousavikhamene el 30 de Mzo. de 2021
Editada: MG el 30 de Mzo. de 2021
I have a huge table (more than 30 columsn) and I would like to delete all columns except the ones that I determined.
Let's say table columns names are: A, AB, TY, IU, OP, JH, KL, GF, DF, CV, MN, GF, QW
and I want to get rid of the all columns except columns: A, JH, DF, CV
Any efficent idea?

Respuesta aceptada

MG
MG el 30 de Mzo. de 2021
Editada: MG el 30 de Mzo. de 2021
Hi,
I'm not sure I understood your question corectly, but here is an example with a matrix with 30 columns and 5 rows with random numbers (as an example). You can create a new matix, keeping e.g. only the 1st, 7th, 10 and 11th column -- such that the new matrix contains only those 4 columns. If you want to keep the orignal table-name (or as in my exmaple, matrix name) for the new table, you can just replace new_table with table in the second line below:
Table = rand(5,30);
new_Table = table(:,[1,7,10,11])
  3 comentarios
Walter Roberson
Walter Roberson el 30 de Mzo. de 2021
it is better to define what to keep when practical
T(:, {'A', 'JH', 'DF' , 'CV'})
MG
MG el 30 de Mzo. de 2021
I agree with Walter, and If you have a table T and you do want to remove columns, say column AB, TY, you could do
T(:,{'AB', 'TY'}) = [];
or if you want to rermmovel say column 2 and 3
T(:,[2 3]) = [];

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings 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