필터 지우기
필터 지우기

how do i shuffle my stimuli so a, b, c, d or e could be asked in any random order?

조회 수: 2 (최근 30일)
Hello I am trying to use 'shuffle' to produce my stimuli randomly but have not been able to figure this out yet. Any help would be greatly appreciated!!
a = randperm(10, 5)-1
for k=1:length(a)
clf;text(0.5,0.5, num2str(a(k)),'FontSize',75);axis off;
pause(1)
clf;
end
for x1 = randsample(a,1), pause(2)
clf;text(0.5,0.5, num2str(x1),'Fontsize',75);axis off
end
pause(3)
b = randperm(10, 4)-1
for k=1:length(b)
clf;text(0.5,0.5, num2str(b(k)),'FontSize',75);axis off;
pause(1)
clf;
end
for x2 = randsample(b,1), pause(2)
clf;text(0.5,0.5, num2str(x2),'FontSize',75);axis off;
end
pause(3)
c = randperm(10, 3)-1
for k=1:length(c)
clf;text(0.5,0.5, num2str(c(k)),'FontSize',75);axis off;
pause(1)
clf;
end
for x3 = randsample(c,1), pause(2)
clf;text(0.5,0.5, num2str(x3),'FontSize',75);axis off;
end
pause(3)
d = randperm(10, 2)-1
for k=1:length(d)
clf;text(0.5,0.5, num2str(d(k)),'FontSize',75);axis off;
pause(1)
clf;
end
for x4 = randsample(d,1), pause(2)
clf;text(0.5,0.5, num2str(x4),'FontSize',75);axis off;
end
pause(3)
e = randperm(10, 1)-1
for k=1:length(e)
clf;text(0.5,0.5, num2str(e(k)),'FontSize',75);axis off;
pause(1)
clf;
end
for x5 = randsample(e,1), pause(2);
clf;text(0.5,0.5, num2str(x5),'FontSize',75);axis off;
end
  댓글 수: 4
Stephen23
Stephen23 2018년 1월 6일
편집: Stephen23 2018년 1월 6일
  • Copy-and-pasting code is a sign that you are doing something wrong. Use a loop instead.
  • Creating lots of sequential variables a, b, c, etc just makes your code more complex, and the data harder to work with.
You need to:
  • Put that data into one array (which could be numeric, cell , structure, table, etc) and then suddenly your task is much simpler because you can trivially use indexing.
  • use randperm and a loop to run that code with a random order of data.
Read this too, if you want to avoid writing slow, inefficient, ugly code:

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by