LoginSignup
1
1

More than 5 years have passed since last update.

MATLAB > array > 行をswapする

Posted at
動作環境
MATLAB Online R2017b

arrayの行をswapしたい。

参考: https://stackoverflow.com/questions/4939738/swapping-rows-and-columns

>> X = [1 2 3; 4 5 6;]

X =

     1     2     3
     4     5     6

以下でswapできるようだ。

>> 
>> X([1 2],:) = X([2 1],:)

X =

     4     5     6
     1     2     3

インデックスを変数において以下のようにswapできる。

>> RHS=1;
>> LHS=2;
>> X([RHS LHS],:)=X([LHS RHS],:)

X =

     4     5     6
     1     2     3
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1