Info

この質問は閉じられています。 編集または回答するには再度開いてください。

[Help] with randomizing a Permutation

1 回表示 (過去 30 日間)
Neurocognitive Psychology
Neurocognitive Psychology 2020 年 3 月 12 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I created an emotion recognition paradigm which shows 144 short video clips of emotional faces.
  • 1-36 angry faces
  • 37-72 fearful faces
  • 73-108 sad faces
  • 109-144 neutral faces
I could need help in randomizing those video clips with the restriction that the same emotion is not shown more than 3 times consecutively. In the end I want a randomized numerical sequence containing all numbers from 1 to 144. Each number only shown once.
I'm glad for any help!

回答 (1 件)

Sai Veeramachaneni
Sai Veeramachaneni 2020 年 3 月 17 日
You can use below function to achieve behavior you need.
function sans = getIds()
emotions = zeros(1,144);
emotions=string(emotions);
for i=1:36
emotions(i)="angry";
end
for i=35:72
emotions(i)="fear";
end
for i=73:108
emotions(i)="sad";
end
for i=109:144
emotions(i)="neutral";
end
sans=1:144;%final answer is stored in this
sequence=1:144; %temporary sequence
pointer=144;
i=1;
while i<=144
tem = randi([1,pointer],1);
temp = sequence(tem);
if (i>3 && (emotions(sans(i-1))~=emotions(temp) ||...
emotions(sans(i-2))~=emotions(temp) ||...
emotions(sans(i-3))~=emotions(temp)))|| i<=3
sans(i)=temp;
i=i+1;
[sequence(tem),sequence(pointer)]=deal(sequence(pointer),sequence(tem));
pointer=pointer-1;
end
end
end

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by