SlideShare a Scribd company logo
1 of 29
Psychtoolbox (PTB)
practical course
by Volodymyr B. Bogdanov
vlabogd@yahoo.com
Kyiv 2017
Day 1:
MATLAB functions important for
building experimental paradigms
Psychophysics Toolbox Version 3 (PTB-3) is a free
set of MATLAB and GNU Octave functions for
vision and neuroscience research.
It makes it easy to synthesize and show accurately
controlled visual and auditory stimuli and interact
with the observer.
http://psychtoolbox.org/
https://www.gnu.org/software/octave/https://mathworks.com/
Why MATLAB?
Because it is one of the most popular,
powerful and flexible data analysis software.
Richard Matthew Stallman
Why GNU Octave?
Because it rather similar to
MATLAB and free!
https://youtu.be/ZPPikY3uLIQ
Specifically, free software means users have
the four essential freedoms: (0) to run the
program, (1) to study and change the program
in source code form, (2) to redistribute exact
copies, and (3) to distribute modified versions.
The GNU Project is a free-software,
mass-collaboration project, first
announced on September 27, 1983 by
Richard Stallman at MIT.
Motivation
This is exactly what you can do with PTB:
you run, study, modify and redistribute
scripts chic can be used for experimental
studies in neuroscience.
Therefore during this course we will use
both Matlab and GNU Octave to learn PTB.
http://kafpson.kpi.ua/Arhiv/Lazarev/dovidnyk_Matlab.pdf
Юрій Федорович Лазарев
Mike X Cohen
http://kafpson.kpi.ua/Arhiv/Lazarev/uml_1n.pdf
MATLAB українською:
Довідник з MATLAB
MATLAB і моделювання динамічних систем
And google for more!
Good books are useful!
John W Eaton
https://www.gnu.org/software/octave/octave.pdf
MATLAB Graphical User Interface (GUI)
Command window
Workspace
Command history
Current folder
GNU Octave Graphical User Interface (GUI)
Command windowWorkspace
Command history
Current folder
Files formats:
*.m – script files (programs, functions) – text files that contain code
*.mat – data files (any kind of variables stored)
Data operations in MATLAB or GNU Octave
Elementary operations
Concatenation
Arithmetic operations
Logical operations
Matrix indexing
Functions
Control (flow) statements
Visualization
Saving, clearing and loading data
[] matrix
OperatorsData classes
Elementary operations
‘’ string
{} cell
a.b structure
MATSAB syntax:
logical
comment is formed with a percent
sign :
% this is a comment, not a command
= equal sign assigns a value to a
variable
a = 7
MATLAB is case-sensitive!
. dot separates decimals
A=7.3
Variables names can contain letters,
numbers but no spaces, only
underscores.
[] square brackets create a matrix.
A_1=[2.5 3.7 4.8]
A_1=[2.5, 3.7, 4.8]
%
=
.
,
;
==
~=
>=
:
MATSAB syntax:
; semicolon adds a raw in a two-
dimensional (rectangular) matrix
A_1=[2.5 3.7 4.8]
A_2=[2 3 4; 3 7 8]
Concatenation is a procedure that allows
to combine two matrixes along one
dimension, given the other dimension is
the same
A_3= [A_1; A_2]
A_3= [A_1, A_2]
A_1
A_2
A_3
Matrix concatenation
1X3
2X3
3X3
Arithmetic operations
A_3 =
2.5000 3.7000 4.8000
2.0000 3.0000 4.0000
3.0000 7.0000 8.0000
You can add, subtract the same number
form all the elements or to multiply or
divide by the same number.
A4 = A_3*2
A4 =
5.0000 7.4000 9.6000
4.0000 6.0000 8.0000
6.0000 14.0000 16.0000
You can also easily make any of such operations
with two matrices of the same dimensions
element by element
A5 = A_3+A4
A5 =
7.5000 11.1000 14.4000
6.0000 9.0000 12.0000
9.0000 21.0000 24.0000
For devision or maltiplication matlab uses
operators ./ and .*
A6 = A_3 .* A4
A6 =
12.5000 27.3800 46.0800
8.0000 18.0000 32.0000
18.0000 98.0000 128.0000
Logical operations and variables
A7=A6>50
A7 =
0 0 0
0 0 0
0 1 1
A8=A6>A_3
A8 =
1 1 1
1 1 1
1 1 1
A9=A7==A8
[] matrix
Data classes
‘’ string
{} cell
a.b structure
logical
Operators
>
==
~=
>=
Indexing
A_3 =
2.5000 3.7000 4.8000
2.0000 3.0000 4.0000
3.0000 7.0000 8.0000
A9 = A_3(1)
A9=A_3(3) % select third element of matrix
A9=A_3( [1 2 3 4 5 6] ) % select from first to sixth element of the matrix
A9 =
2.5000 2.0000 3.0000 3.7000 3.0000 7.0000
A9=A_3(3, 2) % select third raw and secodn column
a mnemonic for this might be "Mr Nice guy" - M rows x N columns
A9 =
7
Operators
%
=
.
,
;
==
~=
>=
:
Indexing
A9=_A3(1:2, 2:3)
A9 =
3.7000 4.8000
3.0000 4.0000
Colon operator is also useful to
generate data arrays
A9=[1:5]
A9 =
1 2 3 4 5
A9=[1:2:10] % a step of 2
A9 =
1 3 5 7 9
A3 =
2.5000 3.7000 4.8000
2.0000 3.0000 4.0000
3.0000 7.0000 8.0000
A9=A_3(1, :)
A9 =
2.5000 3.7000 4.8000
A9=A_3(: , 3)
A9 =
4.8000
4.0000
8.0000
Operators
%
=
.
,
;
==
~=
>=
:
Indexing
A logical matrix can be used for indexing of other matrix
A9 =
1 3 5 7 9
A10 = A9>4
A10 =
0 0 1 1 1
A11=A9(A10)
A11=A9(A9>4)
A11 =
5 7 9
[] matrix
Data classes
''string
{} cell
a.b structure
logical
[] matrix
Data classes
'' string
{} cell
a.b structure
logical
A12='string variable whatever'
A12 =
string variable whatever
A13=A12=='i'
A13 =
Columns 1 through 16
0 0 0 1 0 0 0 0 0 0
1 0 0 0 0 0
Columns 17 through 24
0 0 0 0 0 0 0 0
A13=find(A12=='i')
A13 =
4 11
String variables
[] matrix
Data classes
'' string
{} cell
a.b structure
logical
A13='Kyiv' % city name
A14='Dnipro'
B13=3.4 % population
B14=1.5
Who to combine/concatenate all this information?
Cells or structures!
Cell:
C1={A13, A14; B13, B14}
C1 =
'Kyiv' 'Dnipro'
[3.4000] [1.5000]
Structure must have fields:
S1(1).name=A13
S1(2).name=A14
S1(1).pop=B13
S1(2).pop=B14
S1 =
1x2 struct array with fields:
name
pop
Functions
Functions are programs that can do something useful…
… if you know how to use them!
The most useful function…
– help (!!)
whos
disp
mean
min
max
length
size
sum
diff
sort
zeros
ones
clear
close
Some
functions:
help whos
WHOS List current variables, long form.
WHOS is a long form of WHO. It lists all the variables in the current
workspace, together with information about their size, bytes, class,
etc.
whos
Name Size Bytes Class Attributes
A10 1x5 5 logical
A11 1x3 24 double
A13 1x4 8 char
A14 1x6 12 char
A3 3x3 72 double
A4 3x3 72 double
A5 3x3 72 double
A6 3x3 72 double
A7 3x3 9 logical
A8 3x3 9 logical
A9 1x5 40 double
A_1 1x3 24 double
A_2 2x3 48 double
B13 1x1 8 double
B14 1x1 8 double
C1 2x2 484 cell
S1 1x2 612 struct
a 1x6 48 double
a1 1x6 48 double
help disp
DISP Display array.
DISP(X) displays the array, without printing the array name.
In
all other ways it's the same as leaving the semicolon off an
expression except that empty arrays don't display.
If X is a string, the text is displayed.
See also int2str, num2str, sprintf, rats, format.
HELP function helps to use
other functions
disp(C1{1})
Kyiv
Typically a function has a name, an input and an output.
output = functionname ( input )
A9 =
1 3 5 7 9
M=mean(A9) % averaging
M =
5
D=diff(A9) % consecutive difference
D =
2 2 2 2
Z=zeros(1, 3) % generates [0 0 0]
O=ones(1, 3) % generates [1 1 1]
ZO=[Z,O] % concatenation, gives [0 0 0 1 1 1]
R=repmat(ZO, 1, 2) % replication horizontally two times
Ra=rand(1,12) % random values 0 to 1, 12 elements
P=randperm(12) % values form 1 to 12 in random order
Functions that generate data
Visualization functions
"noise" (Ra) "signal + noise" (Ra+R)
figure(1)
plot(Ra)
figure(2)
plot(R)
hold on
RRa=R+Ra
plot(RRa, 'r')
figure(3)
im(1,:,1)=[RRa] % image requires 3 layes : RGB
im(1,:,2)=[RRa]
im(1,:,3)=[RRa]
image(im/max(RRa)) % normalized to peak amplitude
for
end
Control (flow) statements
pause
switch
case
end
Loops:
if
elseif
end
try
catch
end
while
end
break
figure(2)
for i=1:length(RRa)
if RRa(i)>1
plot(i, RRa(i), 'b.')
else
plot(i, RRa(i), 'g.')
end
drawnow
pause(0.5)
if RRa(i)>1.6
break
end;
end
This program draws blue dots at the plot values
if the value is above 1 and green dots at plot
values if the value is below 1.
Loop breaks if the value is above 1.6
Saving, clearing and loading data
filename='data' % the prefix of the data file
clk=clock % an array of current time [y m d h m s]
for nf = 1:5;
filename = [filename, '_', sprintf('%02.0f', clk(nf))];
% sprintf prints into a string the date parameters
end
save(filename, 'RRa') % save a variable into an *.m file of a given
name
clear RRa % clear the variable RRa
load(filename) % load the file of the given name
filename =
data_2017_10_09_03
Thank you for your interest!
Hopefully soon there will be two more parts:
2. Installation of Psychtoolbox, some demos.
3. Usage of basic Psychtoolbox function for timing,
screen control and keyboard acquisition
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1

More Related Content

What's hot

Matlab ch1 (3)
Matlab ch1 (3)Matlab ch1 (3)
Matlab ch1 (3)mohsinggg
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Data Visualization 2020_21
Data Visualization 2020_21Data Visualization 2020_21
Data Visualization 2020_21Sangita Panchal
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
DataFrame in Python Pandas
DataFrame in Python PandasDataFrame in Python Pandas
DataFrame in Python PandasSangita Panchal
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab OverviiewNazim Naeem
 
Abstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generatorsAbstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generatorsPhilip Schwarz
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
Preparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representationPreparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representationAndres Mendez-Vazquez
 

What's hot (20)

What is matlab
What is matlabWhat is matlab
What is matlab
 
Matlab ch1 (3)
Matlab ch1 (3)Matlab ch1 (3)
Matlab ch1 (3)
 
Matlab Tutorial
Matlab TutorialMatlab Tutorial
Matlab Tutorial
 
Unit 7.2
Unit 7.2Unit 7.2
Unit 7.2
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Data Visualization 2020_21
Data Visualization 2020_21Data Visualization 2020_21
Data Visualization 2020_21
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
DataFrame in Python Pandas
DataFrame in Python PandasDataFrame in Python Pandas
DataFrame in Python Pandas
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
 
Abstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generatorsAbstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generators
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
Unit 2.1
Unit 2.1Unit 2.1
Unit 2.1
 
matlab
matlabmatlab
matlab
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Pandas Series
Pandas SeriesPandas Series
Pandas Series
 
Preparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representationPreparation Data Structures 06 arrays representation
Preparation Data Structures 06 arrays representation
 

Similar to Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1

Similar to Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1 (20)

Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
Matlab1
Matlab1Matlab1
Matlab1
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
 
Matlab
MatlabMatlab
Matlab
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
20100528
2010052820100528
20100528
 
20100528
2010052820100528
20100528
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
Matrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLABMatrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLAB
 
Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
 

More from Volodymyr Bogdanov

Pupillometry tutorial: from A to Z
Pupillometry tutorial: from A to ZPupillometry tutorial: from A to Z
Pupillometry tutorial: from A to ZVolodymyr Bogdanov
 
Peripersonal space journal club, Lyon, CRNL 2019
Peripersonal space journal club, Lyon, CRNL 2019Peripersonal space journal club, Lyon, CRNL 2019
Peripersonal space journal club, Lyon, CRNL 2019Volodymyr Bogdanov
 
Bufacchi 2018 journal_club_short
Bufacchi 2018 journal_club_shortBufacchi 2018 journal_club_short
Bufacchi 2018 journal_club_shortVolodymyr Bogdanov
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...Volodymyr Bogdanov
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2Volodymyr Bogdanov
 
SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2)
SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2) SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2)
SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2) Volodymyr Bogdanov
 

More from Volodymyr Bogdanov (6)

Pupillometry tutorial: from A to Z
Pupillometry tutorial: from A to ZPupillometry tutorial: from A to Z
Pupillometry tutorial: from A to Z
 
Peripersonal space journal club, Lyon, CRNL 2019
Peripersonal space journal club, Lyon, CRNL 2019Peripersonal space journal club, Lyon, CRNL 2019
Peripersonal space journal club, Lyon, CRNL 2019
 
Bufacchi 2018 journal_club_short
Bufacchi 2018 journal_club_shortBufacchi 2018 journal_club_short
Bufacchi 2018 journal_club_short
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 2
 
SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2)
SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2) SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2)
SPM 12 practical course by Volodymyr B. Bogdanov (Kyiv 2015, Day 2)
 

Recently uploaded

Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Genomic DNA And Complementary DNA Libraries construction.
Genomic DNA And Complementary DNA Libraries construction.Genomic DNA And Complementary DNA Libraries construction.
Genomic DNA And Complementary DNA Libraries construction.k64182334
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCEPRINCE C P
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)Jshifa
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Work, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE PhysicsWork, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE Physicsvishikhakeshava1
 
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfSwapnil Therkar
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzohaibmir069
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 

Recently uploaded (20)

Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Genomic DNA And Complementary DNA Libraries construction.
Genomic DNA And Complementary DNA Libraries construction.Genomic DNA And Complementary DNA Libraries construction.
Genomic DNA And Complementary DNA Libraries construction.
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Work, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE PhysicsWork, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE Physics
 
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistan
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 

Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1

  • 1. Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov vlabogd@yahoo.com Kyiv 2017 Day 1: MATLAB functions important for building experimental paradigms
  • 2. Psychophysics Toolbox Version 3 (PTB-3) is a free set of MATLAB and GNU Octave functions for vision and neuroscience research. It makes it easy to synthesize and show accurately controlled visual and auditory stimuli and interact with the observer. http://psychtoolbox.org/ https://www.gnu.org/software/octave/https://mathworks.com/
  • 3. Why MATLAB? Because it is one of the most popular, powerful and flexible data analysis software. Richard Matthew Stallman Why GNU Octave? Because it rather similar to MATLAB and free! https://youtu.be/ZPPikY3uLIQ Specifically, free software means users have the four essential freedoms: (0) to run the program, (1) to study and change the program in source code form, (2) to redistribute exact copies, and (3) to distribute modified versions. The GNU Project is a free-software, mass-collaboration project, first announced on September 27, 1983 by Richard Stallman at MIT. Motivation This is exactly what you can do with PTB: you run, study, modify and redistribute scripts chic can be used for experimental studies in neuroscience. Therefore during this course we will use both Matlab and GNU Octave to learn PTB.
  • 4. http://kafpson.kpi.ua/Arhiv/Lazarev/dovidnyk_Matlab.pdf Юрій Федорович Лазарев Mike X Cohen http://kafpson.kpi.ua/Arhiv/Lazarev/uml_1n.pdf MATLAB українською: Довідник з MATLAB MATLAB і моделювання динамічних систем And google for more! Good books are useful! John W Eaton https://www.gnu.org/software/octave/octave.pdf
  • 5. MATLAB Graphical User Interface (GUI) Command window Workspace Command history Current folder
  • 6. GNU Octave Graphical User Interface (GUI) Command windowWorkspace Command history Current folder
  • 7. Files formats: *.m – script files (programs, functions) – text files that contain code *.mat – data files (any kind of variables stored)
  • 8. Data operations in MATLAB or GNU Octave Elementary operations Concatenation Arithmetic operations Logical operations Matrix indexing Functions Control (flow) statements Visualization Saving, clearing and loading data
  • 9. [] matrix OperatorsData classes Elementary operations ‘’ string {} cell a.b structure MATSAB syntax: logical comment is formed with a percent sign : % this is a comment, not a command = equal sign assigns a value to a variable a = 7 MATLAB is case-sensitive! . dot separates decimals A=7.3 Variables names can contain letters, numbers but no spaces, only underscores. [] square brackets create a matrix. A_1=[2.5 3.7 4.8] A_1=[2.5, 3.7, 4.8] % = . , ; == ~= >= :
  • 10. MATSAB syntax: ; semicolon adds a raw in a two- dimensional (rectangular) matrix A_1=[2.5 3.7 4.8] A_2=[2 3 4; 3 7 8] Concatenation is a procedure that allows to combine two matrixes along one dimension, given the other dimension is the same A_3= [A_1; A_2] A_3= [A_1, A_2] A_1 A_2 A_3 Matrix concatenation 1X3 2X3 3X3
  • 11. Arithmetic operations A_3 = 2.5000 3.7000 4.8000 2.0000 3.0000 4.0000 3.0000 7.0000 8.0000 You can add, subtract the same number form all the elements or to multiply or divide by the same number. A4 = A_3*2 A4 = 5.0000 7.4000 9.6000 4.0000 6.0000 8.0000 6.0000 14.0000 16.0000 You can also easily make any of such operations with two matrices of the same dimensions element by element A5 = A_3+A4 A5 = 7.5000 11.1000 14.4000 6.0000 9.0000 12.0000 9.0000 21.0000 24.0000 For devision or maltiplication matlab uses operators ./ and .* A6 = A_3 .* A4 A6 = 12.5000 27.3800 46.0800 8.0000 18.0000 32.0000 18.0000 98.0000 128.0000
  • 12. Logical operations and variables A7=A6>50 A7 = 0 0 0 0 0 0 0 1 1 A8=A6>A_3 A8 = 1 1 1 1 1 1 1 1 1 A9=A7==A8 [] matrix Data classes ‘’ string {} cell a.b structure logical Operators > == ~= >=
  • 13. Indexing A_3 = 2.5000 3.7000 4.8000 2.0000 3.0000 4.0000 3.0000 7.0000 8.0000 A9 = A_3(1) A9=A_3(3) % select third element of matrix A9=A_3( [1 2 3 4 5 6] ) % select from first to sixth element of the matrix A9 = 2.5000 2.0000 3.0000 3.7000 3.0000 7.0000 A9=A_3(3, 2) % select third raw and secodn column a mnemonic for this might be "Mr Nice guy" - M rows x N columns A9 = 7 Operators % = . , ; == ~= >= :
  • 14. Indexing A9=_A3(1:2, 2:3) A9 = 3.7000 4.8000 3.0000 4.0000 Colon operator is also useful to generate data arrays A9=[1:5] A9 = 1 2 3 4 5 A9=[1:2:10] % a step of 2 A9 = 1 3 5 7 9 A3 = 2.5000 3.7000 4.8000 2.0000 3.0000 4.0000 3.0000 7.0000 8.0000 A9=A_3(1, :) A9 = 2.5000 3.7000 4.8000 A9=A_3(: , 3) A9 = 4.8000 4.0000 8.0000 Operators % = . , ; == ~= >= :
  • 15. Indexing A logical matrix can be used for indexing of other matrix A9 = 1 3 5 7 9 A10 = A9>4 A10 = 0 0 1 1 1 A11=A9(A10) A11=A9(A9>4) A11 = 5 7 9 [] matrix Data classes ''string {} cell a.b structure logical
  • 16. [] matrix Data classes '' string {} cell a.b structure logical A12='string variable whatever' A12 = string variable whatever A13=A12=='i' A13 = Columns 1 through 16 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 Columns 17 through 24 0 0 0 0 0 0 0 0 A13=find(A12=='i') A13 = 4 11 String variables
  • 17. [] matrix Data classes '' string {} cell a.b structure logical A13='Kyiv' % city name A14='Dnipro' B13=3.4 % population B14=1.5 Who to combine/concatenate all this information? Cells or structures! Cell: C1={A13, A14; B13, B14} C1 = 'Kyiv' 'Dnipro' [3.4000] [1.5000] Structure must have fields: S1(1).name=A13 S1(2).name=A14 S1(1).pop=B13 S1(2).pop=B14 S1 = 1x2 struct array with fields: name pop
  • 18. Functions Functions are programs that can do something useful… … if you know how to use them!
  • 19. The most useful function… – help (!!) whos disp mean min max length size sum diff sort zeros ones clear close Some functions:
  • 20. help whos WHOS List current variables, long form. WHOS is a long form of WHO. It lists all the variables in the current workspace, together with information about their size, bytes, class, etc. whos Name Size Bytes Class Attributes A10 1x5 5 logical A11 1x3 24 double A13 1x4 8 char A14 1x6 12 char A3 3x3 72 double A4 3x3 72 double A5 3x3 72 double A6 3x3 72 double A7 3x3 9 logical A8 3x3 9 logical A9 1x5 40 double A_1 1x3 24 double A_2 2x3 48 double B13 1x1 8 double B14 1x1 8 double C1 2x2 484 cell S1 1x2 612 struct a 1x6 48 double a1 1x6 48 double
  • 21. help disp DISP Display array. DISP(X) displays the array, without printing the array name. In all other ways it's the same as leaving the semicolon off an expression except that empty arrays don't display. If X is a string, the text is displayed. See also int2str, num2str, sprintf, rats, format. HELP function helps to use other functions disp(C1{1}) Kyiv
  • 22. Typically a function has a name, an input and an output. output = functionname ( input ) A9 = 1 3 5 7 9 M=mean(A9) % averaging M = 5 D=diff(A9) % consecutive difference D = 2 2 2 2
  • 23. Z=zeros(1, 3) % generates [0 0 0] O=ones(1, 3) % generates [1 1 1] ZO=[Z,O] % concatenation, gives [0 0 0 1 1 1] R=repmat(ZO, 1, 2) % replication horizontally two times Ra=rand(1,12) % random values 0 to 1, 12 elements P=randperm(12) % values form 1 to 12 in random order Functions that generate data
  • 24. Visualization functions "noise" (Ra) "signal + noise" (Ra+R) figure(1) plot(Ra) figure(2) plot(R) hold on RRa=R+Ra plot(RRa, 'r') figure(3) im(1,:,1)=[RRa] % image requires 3 layes : RGB im(1,:,2)=[RRa] im(1,:,3)=[RRa] image(im/max(RRa)) % normalized to peak amplitude
  • 26. figure(2) for i=1:length(RRa) if RRa(i)>1 plot(i, RRa(i), 'b.') else plot(i, RRa(i), 'g.') end drawnow pause(0.5) if RRa(i)>1.6 break end; end This program draws blue dots at the plot values if the value is above 1 and green dots at plot values if the value is below 1. Loop breaks if the value is above 1.6
  • 27. Saving, clearing and loading data filename='data' % the prefix of the data file clk=clock % an array of current time [y m d h m s] for nf = 1:5; filename = [filename, '_', sprintf('%02.0f', clk(nf))]; % sprintf prints into a string the date parameters end save(filename, 'RRa') % save a variable into an *.m file of a given name clear RRa % clear the variable RRa load(filename) % load the file of the given name filename = data_2017_10_09_03
  • 28. Thank you for your interest! Hopefully soon there will be two more parts: 2. Installation of Psychtoolbox, some demos. 3. Usage of basic Psychtoolbox function for timing, screen control and keyboard acquisition