フィルターのクリア

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

2 ビュー (過去 30 日間)
Michael Davies
Michael Davies 2018 年 1 月 6 日
編集済み: Walter Roberson 2018 年 1 月 6 日
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:
Michael Davies
Michael Davies 2018 年 1 月 6 日
Thank you for your advice!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by