how to remove repetition in matrix without changing length
Ältere Kommentare anzeigen
Hi,
I'm trying to create an experiment with matlab and I am using 2 columns in a matrix with number I have randomized according to an index.
I cannot however have a repetition within one column and the two columns have to stay separated and keep the length of 36 elements.
so this is how I created my matrix:
for n = 1:6
l((n-1)*6+1:n*6,1)=n
l((n-1)*6+1:n*6,2)=[1:6]
end
vec_index=randperm(36)
vec_randomised=l(vec_index',:)
which gives me this:
5 3
4 2
4 1
4 6
5 5
6 3
1 5
1 2
1 6
6 5
3 2
6 1
5 4
1 4
2 3
3 5
5 2
2 2
6 2
4 3
2 6
3 6
5 1
2 5
6 4
2 1
6 6
3 4
3 3
4 4
5 6
1 1
2 4
3 1
1 3
4 5
as you can see there are repetitions for example the 3x4 in the first column.
I made a for-loop to detect the repetition but this does not help me to remove them and keeping the same numbers/amount of numbers in the column.
I also tried shuffle but this gives me different numbers.
I hope I need this as I want to couple this array to words and sounds (which I'm also failing at)
Hopefully someone can help! thx
2 Kommentare
EDITED, Code formatted.
What exactly is your question? I do not really understand this sentence: "I cannot however have a repetition within one column and the two columns have to stay separated and keep the length of 36 elements." Can the 2 columns do anything but staying separated?
What is the criterion for the matrix? Values from 1 to 6, the values in a row must be different, neighboring elements in the columns must be different?
Ilse Coolen
am 21 Dez. 2015
Akzeptierte Antwort
Weitere Antworten (1)
harjeet singh
am 21 Dez. 2015
use this code
for n = 1:6
l((n-1)*6+1:n*6,1)=n;
l((n-1)*6+1:n*6,2)=[1:6];
end
c=1:36;
B=c(randperm(length(l)));
vec_randomised=l(B',:);
3 Kommentare
Ilse Coolen
am 21 Dez. 2015
harjeet singh
am 21 Dez. 2015
where you are getting the same numbers? in which row?
vec_randomised =
1 5
2 5
5 5
5 2
3 4
6 2
2 6
5 3
6 3
4 3
1 1
3 2
1 2
6 1
2 3
5 4
4 4
2 4
4 5
1 3
6 6
5 6
3 6
2 1
1 4
3 1
6 5
4 1
4 6
5 1
1 6
2 2
3 3
6 4
3 5
4 2
Ilse Coolen
am 21 Dez. 2015
Kategorien
Mehr zu Timing and presenting 2D and 3D stimuli finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!