shuffle matrix element in matlab

后端 未结 2 1496
夕颜
夕颜 2020-12-03 17:32

I have a martix and want to shuffle element of it .

x=[1 2 5 4 6 ]

after shuffle(something like this)

x=[2 4 6 5 1]    
         


        
2条回答
  •  难免孤独
    2020-12-03 18:11

    1. obtain shuffled indices using randperm

      idx = randperm(length(x));
      
    2. use indices to obtain shuffled vector

      xperm = x(idx);

提交回复
热议问题