re-arranging of columns

1 次查看(过去 30 天)
aditi
aditi 2014-4-4
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

采纳的回答

Viju
Viju 2014-4-4
编辑:Viju 2014-4-4
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 个评论
aditi
aditi 2014-4-4
ohh okay.... thanks viju..
so here 'x' is the variable in which i load the data file?? right???

请先登录,再进行评论。

更多回答(1 个)

Jos (10584)
Jos (10584) 2014-4-4
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

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by