re-arranging of columns

1 visualización (últimos 30 días)
aditi
aditi el 4 de Abr. de 2014
Respondida: Jos (10584) el 4 de Abr. de 2014
hi everyone..
i have a data file with 24 columns and 125 rows... I want to bring 23rd column after column 4... how will i do that... please help

Respuesta aceptada

Viju
Viju el 4 de Abr. de 2014
Editada: Viju el 4 de Abr. de 2014
Once you import this data into a MATLAB variable, there are multiple methods. One way is as follows, where x is the data and y is where I am storing the new data.
y = [x(:,1:4) x(:,23) x(:,5:22) x(:,24)]
  1 comentario
aditi
aditi el 4 de Abr. de 2014
ohh okay.... thanks viju..
so here 'x' is the variable in which i load the data file?? right???

Iniciar sesión para comentar.

Más respuestas (1)

Jos (10584)
Jos (10584) el 4 de Abr. de 2014
No need for concatenation …
A = load('mydatafile.txt') % only numbers separated by spaces/tabs
A(:,[4 23]) = A(:,[23 4]) % switch columns 4 and 23

Categorías

Más información sobre Workspace Variables and MAT-Files 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