variable positions in matrix

1 view (last 30 days)
Linden
Linden on 6 May 2014
Answered: Image Analyst on 6 May 2014
Hi Is it possible to easily switch the variable positions in a matirx. For example, I have 4 time series variables, x1, x2, x3 and x4. They form a matrix [x1 x2 x3 x4]. In my program, I want to give an indix that to each of these variables such that if I put 2 1 3 4, the matrix will become [x2 x1 x3 x4]. Many thanks

Answers (1)

Image Analyst
Image Analyst on 6 May 2014
I think you just did it, didn't you? If you want and just have an array x, you can do
new_x = [x(:,2), x(:, 1), x(:, 3), x(:, 4)];

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!