I want to create multiple buffers one after the other. How do ensure that they show in a random order?

3 次查看(过去 30 天)
Ive got this piece of script. The intent is for it to display 2 squares and have a word in the centre. Im hoping to duplicate this many times and changing the word, font and the colours of the 2 cgrects. My question is, how do i randomise the order that theyre shown in once its been duplicated say for example 20 times.
cgloadlib
cgopen(1,0,0,0)
cgscale(30)
cgalign('r','c')
cgpencol(1,0,0)
cgrect(-6,-4,7,7)
cgalign('l','c')
cgpencol(0,0,1)
cgrect(6,-4,7,7)
cgpencol(1,0,0)
cgfont('calibri',4)
cgtext((colorword(:,1)),0,6);
cgflip
wait(5000)
would i have to loop the whole thing and set it up to show randomly? IF SO how do i do this?

回答(1 个)

dpb
dpb 2019-12-10
Simplest would be to create N objects in (say) a cell array. Then generated a randomized indexing vector as |randperm
idxrand=randperm(N);
and then display objects in that order.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by