How to randomly shuffle neighbouring elements in a matrix ?
Show older comments
Hi ! I have an array like:
A = [ a b c
d e f
g h i ]
How can I randomly shuffle the elements within the array so that neighboring elements (also diagonal) have a higer probability to be shuffled between each others ?
The result I would like to get is something like, but of course at every iteration it would be different.
A = [ b a c
g h e
d f i ]
Hope my question is clear. Thanky for your help
7 Comments
KALYAN ACHARJYA
on 23 Mar 2019
have a higer probability to be shuffled between each others ?
???
John D'Errico
on 23 Mar 2019
Edited: John D'Errico
on 23 Mar 2019
When you ask a vague question, with statements like "have a higher probability" then expect to get confused responses.
1 is a higher probabiltiy than 0. Is that sufficient?
You need to define which elements can get swapped with which others. Is this always a 3x3 matrix? And you need to define what you mean by higher, and how you wouldquantify that.
Alberto Scarampi del Cairo
on 23 Mar 2019
Image Analyst
on 23 Mar 2019
What is an iteration?
In the meantime, you can get a shuffling order with randperm().
Alberto Scarampi del Cairo
on 23 Mar 2019
Image Analyst
on 23 Mar 2019
Edited: Image Analyst
on 23 Mar 2019
So for iteration 1 do you shuffle the whole A, or do you just shuffle neighbors of a? Then for the second iteration, do you shuffle the whole A again, or do you shuffle just the neighbors of the value in the location of the original "b" (in other workds, shuffle neighbors of the (2,1) element which would be the 5 neighboring elements at (1,1), (1,2), (2,2), (3,1) and (3,2)?
Give an example of what A might look like after iteration 1, and iteration 2.
Alberto Scarampi del Cairo
on 23 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics and Optimization 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!