Dim arrStim(TrialList.size),TypeCount(3),arrTmp(7) As Integer Dim i,j,k As Integer Dim bools As Boolean For i = 1 To UBound(arrtmp) arrstim(i).stim=Triallist.GetAttrib (i,"stim") arrstim(i).stimtype=triallist.GetAttrib (i,"stimtype") Next For i=1 To TrialList.size/7 Do bools=True RandomizeArray arrstim,7*(i-1)+1,71 For j=7(i-1)+1 To 7*1-1 If arrtmp(j).stimtype=arrtmp(j+1).stimtype="B" Or arrtmp(j).stimtype=arrtmp(j+1).stimtype="C" Then bools=False Exit For Else If arrtmp(1).stimtype="B" Or arrtmp(2).stimtype="B" Or arrtmp(139).stimtype="B" Or arrtmp(140).stimtype="B" Or arrtmp(1).stimtype="C" Or arrtmp(2).stimtype="C" Or arrtmp(139).stimtype="C" Or arrtmp(140).stimtype="C" bools=False Exit For End If End If Next j Loop Until bool=True Next i For i=1 To UBound(arrstim) TrialList.SetAttrib i,"stim",arrstim(i).stim TrialList.SetAttrib i,"stimtype",arrstim(i).stimtype Next TrialList.Reset 要求:有三种实验材料,A材料100个、BC材料各20个。BC不能呈现在首尾的前后两个刺激上。BC同种材料不能重复呈现,BC可以挨着呈现。对A材料不反应,反应位错;对B材料按“f”键进行反应,C材料按“j”键进行反应。实验过程为:注视点800毫秒→刺激界面(无限时间) →反馈界面。设计要求: 1)请用“化整为零+随机打乱判断”法进行设计。 对以上编码进行修改
时间: 2024-02-15 14:05:55 浏览: 29
这段代码的主要作用是实现一个实验的材料随机排列,并且保证BC材料不能出现在首尾的前后两个刺激上,同种材料也不能重复呈现。代码的修改如下:
```
Dim arrStim(TrialList.size), TypeCount(3), arrTmp(7) As Integer
Dim i, j, k As Integer
Dim bools As Boolean
For i = 1 To UBound(arrtmp)
arrstim(i).stim = Triallist.GetAttrib(i, "stim")
arrstim(i).stimtype = Triallist.GetAttrib(i, "stimtype")
Next
' 首先将A材料随机排列
RandomizeArray arrstim, 1, 100
' 然后将BC材料随机排列
RandomizeArray arrstim, 101, 120
RandomizeArray arrstim, 121, 140
' 接下来对BC材料进行判断
For i = 1 To TrialList.size / 7
Do
bools = True
' 随机打乱7个材料的顺序
RandomizeArray arrstim, 7 * (i - 1) + 1, 7
' 判断首尾两个材料是否为BC,若是,则重新随机排列
If arrstim(7 * (i - 1) + 1).stimtype = "B" Or arrstim(7 * (i - 1) + 1).stimtype = "C" Or arrstim(7 * i).stimtype = "B" Or arrstim(7 * i).stimtype = "C" Then
bools = False
Continue For
End If
' 判断7个材料中是否有同种BC材料,若有,则重新随机排列
For j = 7 * (i - 1) + 1 To 7 * i - 1
If arrstim(j).stimtype = "B" And arrstim(j + 1).stimtype = "B" Or arrstim(j).stimtype = "C" And arrstim(j + 1).stimtype = "C" Then
bools = False
Exit For
End If
Next j
Loop Until bools = True
Next i
' 将随机排列后的材料写回到TrialList中
For i = 1 To UBound(arrstim)
TrialList.SetAttrib i, "stim", arrstim(i).stim
TrialList.SetAttrib i, "stimtype", arrstim(i).stimtype
Next
TrialList.Reset
```
修改后的代码首先将100个A材料和20个BC材料分别随机排列,然后对BC材料进行判断和随机排列,最后将随机排列后的材料写回到TrialList中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)