필터 지우기
필터 지우기

randomization of a vector by blocks

조회 수: 2 (최근 30일)
Alejandro Estudillo
Alejandro Estudillo 2018년 6월 25일
댓글: Alejandro Estudillo 2018년 6월 26일
I am programming an experiment. Let's say that my experiment has 13 different conditions. Each condition is presented twice per block. There are two blocks in total. This makes a total of 52 trials.
conditions = repmat(1:13,1,4)
I can randomize the variable condition.
conditionsrand = conditions(randperm(length(conditions)))
However, I would like to do this randomization by block. That is every 26 trials there should be two instances of each condition. I think that this must be something easy, but I cannot find the solution.
Any idea?
Thanks!

채택된 답변

Jos (10584)
Jos (10584) 2018년 6월 25일
편집: Jos (10584) 2018년 6월 25일
C = repmat(1:13,1,2) % conditions per block
% [block1 block2]
rC = [C(randperm(numel(C))) C(randperm(numel(C)))] % *corrected
  댓글 수: 3
Jos (10584)
Jos (10584) 2018년 6월 25일
I forgot two closing brackets, which is now corrected. Do you want to create all trials at once? An easy alternative:
C = 1:5
numC = numel(C)
numCperBlock = 2
numBlocks = 3
[~,r] = sort(rand(numC, numCperBlock * numBlocks))
rC = reshape(C(r),1,[])
Alejandro Estudillo
Alejandro Estudillo 2018년 6월 26일
thanks! that works perfectly!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by