stroop效应matlab实验

1 打开matlab,打开test1.m

 

点击运行,若出现选择 更改文件夹

2  引导界面

 

(在这个界面,只许用户鼠标点击开始,其余的别乱按按键。 记得将打字法关掉,切换到小写)

3 做题界面

 

根据颜色选择按键,直到做完题。80到题

界面出现,鼠标一定要点击下界面,不然键盘按键无效不起作用。

4结果

这里只统计正确的次数以及对应累加的时间。

2文件

 

 

function varargout = test1(varargin)
% TEST1 MATLAB code for test1.fig
%      TEST1, by itself, creates a new TEST1 or raises the existing
%      singleton*.
%      
%      H = TEST1 returns the handle to a new TEST1 or the handle to
%      the existing singleton*.
%      
%      TEST1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TEST1.M with the given input arguments.
%
%      TEST1('Property','Value',...) creates a new TEST1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before test1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to test1_OpeningFcn via varargin.
%      
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help test1

% Last Modified by GUIDE v2.5 13-Jan-2019 00:41:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @test1_OpeningFcn, ...
                   'gui_OutputFcn',  @test1_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

global t0; 
t0=clock;




% --- Executes just before test1 is made visible.
function test1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to test1 (see VARARGIN)

% Choose default command line output for test1
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes test1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = test1_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

function [color_c] = tran_keytocolor(Key)
%判断是否正确
 color_c='';
    switch Key
     case 'a' 
         color_c='r';%红色
     case 's' 
         color_c='g'; %绿色
     case 'd' 
         color_c='b';%蓝色
     case 'f' 
         color_c='y';%黄色
            
     otherwise
         warning('按键无效! 请选择 a s d f 按键!');
    end

function [num_r] = tran_leibie(idv,handles)
%判断是否正确
 num_r='';
 
   switch idv  % 判断随机图的题型类
     case '1'
       num_r=  handles.r1;
     case '2'
      num_r=  handles.r2;
     case '3'
      num_r=  handles.r3;
     case '4'
      num_r= handles.r4;
     otherwise
         warning('题目类型找不到!');
   end
    
    
% --- Executes on key press with focus on figure1 and none of its controls.
function figure1_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  structure with the following fields (see MATLAB.UI.FIGURE)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)
% 定义  a    s     d     f    g    h     j   按键对应颜色
% 获取题号
all_number=80;

num=get(handles.text_num,'Value');

global word;
global color;
global randi5_16;

word={
'1',  '1',  '1',  '1',  '2',  '2',  '2',  '2',  '3',  '3',  '3',  '3', '4', '4',  '4' , '4';
'红', '绿', '蓝', '黄' ,'红', '绿', '蓝', '黄' , '我', '爱', '中', '国','洪', '皇', '拦', '滤';
};
    
color={'r',  'g',  'b',  'y'  ,'g',  'b', 'y' ,  'r' , 'r',  'y',  'b',  'g', 'g',  'b',  'y ', 'r';};
   
randi5_16=[1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16 2 6 10 14 4 8 12 16 1 5 9 13 3 7 11 15 10 14 4 8 9 13 3 7 11 15 1 5 12 16 2 6 4 8 9 13 12 16 2 6 10 14 3 7 11 15 1 5 9 13 12 16 3 7 11 15 2 6 10 14 1 5 4 8;];


%1获取按键
Key= get(gcf,'CurrentCharacter');
%按键转换成颜色
color_c = tran_keytocolor(Key);
%  warning(color_c);
%2 判断是哪个随机图
ID=handles.randid;

if Key =='a'|| Key =='s' || Key =='d'|| Key =='f' & num<=all_number %判断按下的是否是回车键
    
    
      global t1; 
      t1=clock;
      global t0;
      handles.time.Value=etime(t1, t0);
      handles.time.String=handles.time.Value;
      t0=clock;

%2获取当前显示字体控件 
text_show1=handles.text_show;

%3 获取题目类别
leibie_num=word{1,ID.Value};
if leibie_num=='1'
   if handles.color_temp.String==color_c & num<=all_number
       num_r=  handles.r1;
       set(num_r, 'Value',num_r.Value+1);
       set(num_r, 'String',num_r.Value); 
       handles.t1.Value= handles.t1.Value+ handles.time.Value;
       handles.t1.String= handles.t1.Value;
   end
elseif leibie_num=='2'
      if handles.color_temp.String==color_c & num<=all_number
      num_r=  handles.r2;
       set(num_r, 'Value',num_r.Value+1);
       set(num_r, 'String',num_r.Value); 
          handles.t2.Value= handles.t2.Value+ handles.time.Value;
          handles.t2.String= handles.t2.Value;
      end
elseif leibie_num=='3'
      if handles.color_temp.String==color_c & num<=all_number
      num_r=  handles.r3;
      set(num_r, 'Value',num_r.Value+1);
      set(num_r, 'String',num_r.Value); 
        handles.t3.Value= handles.t3.Value+ handles.time.Value;
          handles.t3.String= handles.t3.Value;
      end
elseif leibie_num=='4'
      if handles.color_temp.String==color_c & num<=all_number
      num_r= handles.r4;
      set(num_r, 'Value',num_r.Value+1);
      set(num_r, 'String',num_r.Value); 
        handles.t4.Value= handles.t4.Value+ handles.time.Value;
         handles.t4.String= handles.t4.Value;
      end
end

% 修改题号+1
if num<=all_number-1 
temp1=handles.text_num;
set(temp1, 'Value',num+1);
set(temp1, 'String',num+1);

 %ID1=randi(16,1);
 ID1=randi5_16(temp1.Value);
 
 set(ID, 'Value',randi5_16(temp1.Value));
 set(ID, 'String',randi5_16(temp1.Value));
 set(text_show1, 'String',word(2,randi5_16(temp1.Value)));
 set(text_show1, 'ForegroundColor',color{randi5_16(temp1.Value)});
 set(handles.color_temp, 'String',color{randi5_16(temp1.Value)});
else
 
  temp1=handles.text_num;
  set(temp1, 'Value',all_number+1);
  open('result.fig') 
  
  handles.text10.Visible='on';
  handles.text11.Visible='on';
  handles.text14.Visible='on';
  handles.text15.Visible='on';
  handles.text16.Visible='on';
  
  handles.text12.Visible='on';
  handles.r1.Visible='on';
  handles.r2.Visible='on';
  handles.r3.Visible='on';
  handles.r4.Visible='on';
  
  handles.text8.Visible='on';
  handles.t1.Visible='on';
  handles.t2.Visible='on';
  handles.t3.Visible='on';
  handles.t4.Visible='on';
  
end
end






% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.text32.Visible='off';
handles.text36.Visible='off';
handles.text38.Visible='off';
handles.pushbutton2.Visible='off';
handles.text_show.Visible='on';
global t0; 
t0=clock;


% --- Executes on key press with focus on pushbutton2 and none of its controls.
function pushbutton2_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)

handles.text32.Visible='off';
handles.text36.Visible='off';
handles.text38.Visible='off';
handles.pushbutton2.Visible='off';
handles.text_show.Visible='on';
global t0; 
t0=clock;

  

猜你喜欢

转载自www.cnblogs.com/kekeoutlook/p/10262648.html