How to shuffle some arrays of a matrix?
2 次查看(过去 30 天)
显示 更早的评论
Hi Does any one know how can I randomly shuffle some arrays in a matrix? for example
a=[1 2 3 4 5 6]
I need to choose from for example 2 to 5 and shuffle them like this
a=[1 5 4 2 3 6]
1 个评论
Adam
2014-8-12
Do you mean you need to choose index positions 2 to 5 or actual numbers 2 to 5? Or is your start array always just a sorted contiguous sequence so they amount to the same thing?
回答(5 个)
Michael Haderlein
2014-8-12
x=rand(1,6);
[~,y]=sort(x);
a(y)
If a is always just 1:6, you can directly use y instead.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!