matlab class 7 hristiyan kourtev & xiaotao su, ph.d. visual psychophysicist & it group...
TRANSCRIPT
![Page 1: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/1.jpg)
Matlab Class 7
Hristiyan Kourtev &Xiaotao Su, Ph.D.
Visual Psychophysicist & IT Group LeaderRutgers Center for Cognitive Science (RuCCS)
![Page 2: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/2.jpg)
RuCCS
Accurate Timing
• GetSecs is a psychtoolbox function that provides highly accurate timing.
• It returns the number of seconds since the machine has started up
• To test precision on your machine, type:GetSecsTick
a = GetSecsGetSecs – aGetSecs – aGetSecs – aGetSecs – a
Command Window:
![Page 3: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/3.jpg)
RuCCS
KbCheck
• KbCheck is used to check if a key is being pressed and to find out what key is being pressed.
• Returns three values
• [key_press, secs, key_code]=KbCheck
![Page 4: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/4.jpg)
RuCCS
KbCheck
• KbCheck is used to check if a key is being pressed and to find out what key is being pressed.
• Returns three values
• [key_press, secs, key_code]=KbCheck
1 or 0 depending on if there was a key press
Time that this test took place (This is from GetSecs function)
Vector representing all of the input keys. Elements in the vector are set to 1 if pressed or 0 if not
![Page 5: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/5.jpg)
RuCCS
Speed Test Game%speed_test.m%tests your reaction timeWaitSecs(1);disp('Ready?');num_sec_to_start = rand*5+1;WaitSecs(num_sec_to_start);too_soon = 0;timer = GetSecs;while ((GetSecs-timer)<num_sec_to_start) ... && (~too_soon) [too_soon, secs, keyCode] = KbCheck; if(too_soon) break; endendif(too_soon) disp('you pressed the key too early');else
disp('NOW!'); timer = GetSecs; while 1 [key_is_down, secs, key_code] = KbCheck; if(key_is_down) break end end elapsed_time = secs - timer; disp(['Your time was ', num2str(elapsed_time)]);
end
![Page 6: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/6.jpg)
RuCCS
Task 1
• Make it so if someone presses a key too early, the program give a message and exits.
• [key_press, secs, key_code]=KbCheck
1 or 0 depending on if there was a key press
Time that this test took place
(This is from GetSecs function)
Vector representing all of the input keys. Elements in the vector are set to 1 if pressed or 0 if not
(Tip:first remove WaitSecs
![Page 7: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/7.jpg)
RuCCS
Speed Test Game%speed_test.m%tests your reaction timeWaitSecs(1);disp('Ready?');num_sec_to_start = rand*5+1;WaitSecs(num_sec_to_start);too_soon = 0;timer = GetSecs;while ((GetSecs-timer)<num_sec_to_start) ... && (~too_soon) [too_soon, secs, keyCode] = KbCheck; if(too_soon) break; endendif(too_soon) disp('you pressed the key too early');else
disp('NOW!'); timer = GetSecs; while 1 [key_is_down, secs, key_code] = KbCheck; if(key_is_down) break end end elapsed_time = secs - timer; disp(['Your time was ', num2str(elapsed_time)]);
end
![Page 8: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/8.jpg)
RuCCS
What key was pressed?
• The third returned value is a vector representing all the keys with 1’s for pressed keys and zeros for keys that aren’t pressed
• To find the value of the key, use:key_name = KbName(key_code);This will return a string corresponding to that key_code
![Page 9: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/9.jpg)
RuCCS
Simple program to find key mapping names
% get_key_name.m%find out what the name of the key is WaitSecs(1);KbWait;[key_is_down, secs, key_code] = KbCheck;name = KbName(key_code);disp(name);
![Page 10: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/10.jpg)
RuCCS
KbName works the other way around as well
As you have seen:• key_name = KbName(key_code);
You can also do the following:• return_key = KbName(‘return’);• esc_key = KbName(‘esc’);• up_key = KbName(‘up’);
And this will get you the index of the element in the key_code vector that corresponds to that key
![Page 11: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/11.jpg)
RuCCS
key_code vector when esc is pressed
0 0 …. 0 0 1 0 0 …..
(1) (2) …. (25) (26) (27) (28) (29) ….
key_code vector:
Values:
Indexes
So, key_code(27) is 1
esc’s key code is 27
![Page 12: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/12.jpg)
RuCCS
Exit on esc
%exit_on_esc.m esc_key = KbName('esc');i = 0;while 1 i = i+1 [key_is_down, secs, key_code] = KbCheck; if(key_code(esc_key)) break; endenddisp('Good Bye');
![Page 13: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/13.jpg)
RuCCS
Moving Dot
%moving_dot.mclear all;screen_setup; up_key = KbName('up');down_key = KbName('down');left_key = KbName('left');right_key = KbName('right');esc_key = KbName('esc'); shape = [20, 20, 100, 100];color = [255, 0, 255];tic
while toc<10 Screen(window, ‘FillOval', … color, shape); flip; [key_is_down, secs, key_code] … = KbCheck; if(key_code(esc_key)) break endendclear screen;
![Page 14: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/14.jpg)
RuCCS
Task 2
• Draw a circle
• Make it so the arrow keys will move the circle
• Make sure the circle cannot go outside of the boundaries of the screen.
![Page 15: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/15.jpg)
RuCCS
Task 3 - color differentiation (part 1)
1. Take subject name
2. screen_setup– trial loop (start with 5)
color = [rand*255, rand*255, rand*255]– put circles 1-4 on the screen
• one of the four circles will be slightly off (start with +/-50), color from the others on one of the three color dimensions (randomly chose dimension); careful that your deviation doesn’t go >255 or <0
• The subject will click on the circle they feel is different• record data (whatever would be useful)• if the subject was right in the last loop, the amount the color is off is
cut in half, otherwise, increase by half
3. save trial data to csv
tip: make a function to determine if the cursor is in a shape
function is_in = in_shape(vect, mouse_x, mouse_y)
![Page 16: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/16.jpg)
RuCCS
Task 3 - color differentiation (part 2)
Further additions:1. allow the subject to press 1 - 4 to select a circle (using KbCheck)2. put numbers in the circles
Hint: You need to use the following commands:Screen('TextFont', window, fontName*);
Screen('TextSize', window, fontSize**);Screen('DrawText', window, textString, x, y, textColor);
*fontName can be “Arial”, “Verdana” or other*fontSize can be any number. Start with around 20 and adjust as needed
![Page 17: Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)](https://reader036.vdocuments.us/reader036/viewer/2022082818/56649e7f5503460f94b84018/html5/thumbnails/17.jpg)
RuCCS
Deploying Matlab Programs on other machines
• The Matlab Builder/Deploytool – ‘deploytool’
• The Matlab Component Runtime (MCR)
• Creating a standalone version of a Matlab program (Windows)
• Creating a standalone version of a Matlab program (OSX)
• The .NET Builder and deploying to the web