Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Michael Davies
Michael Davies le 6 Jan 2018
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 commentaires
Stephen23
Stephen23 le 6 Jan 2018
Modifié(e) : Stephen23 le 6 Jan 2018
  • 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:
Michael Davies
Michael Davies le 6 Jan 2018
Thank you for your advice!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by