how do i shuffle my stimuli so a, b, c, d or e could be asked in any random order?
1 次查看(过去 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
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!