Matlab-Exercises 2 PDF
Matlab-Exercises 2 PDF
23
b) Put the second column of G into N
c) Add them together
d) Multiple ONLY the third column of A by C and put the result back in the third
column of A. You can use several steps if you want, but it is possible do use just one
line.
e) Find the Dth row of H (i.e. row 2) and sum all the elements in that row
f) Create a new matrix K made up of A in the first 2 rows and B in the next 2 rows.
4) Look at difference between array multiplication and matrix multiplication
a) Try A*B (you will get an error)
b) Try A*B’(that is, A matrix multiplied by B transpose), and compare to A.*B (that
is, array multiplication of A and B)
5) Find the maximum values of each column of J, and find the minimum value of each row of B
Type help max and help min if you need to
Exercise C: Logicals
Make sure you type clear all before starting, and load the dataset ex_C.mat. This data set
contains 3 vectors:
rt is a vector of reaction times of one subject on a visual attention task.
cue is a vector describing if the cue was valid (1), invalid (2) or absent (3).
side is a vector describing if the target was on the left (1) or right (2) of the screen.
1) Create a logical vector called valid which defines all the trials with valid cues
2) Use this to find the mean and standard deviation of reaction time on valid cues
3) Error trials are ones where the reaction time is less than 100 msec or more than 1000 msec.
Create a logical vector called error defining which trials are errors
4) Using both error and valid to find the mean and standard deviation of reaction times for
correct valid trials
5) Create a logical vector called side which you can use to determine the side of stimulus
presentation.
6) Does mean reaction time on all trials vary with side? What about reaction time of valid trials
only?
24
5) Do subjects 2 and 3 agree on any of their ratings? How many?
6) Find the mean disagreement between subjects 1 and 2 (use abs)
7) Faces 4, 10, 12 and 18 were much older than the other faces. Were they ranked as less
attractive?
8) Sort the data according to the stimulus number (use sortrows)
25
c) Modify the switch statement to give you the remainder of A divided by 3 (use the
rem command)
d) Put the whole switch loop within a for loop that counts though A from 50 to 70.
Your program should print what remainder of A/3 in words for each value of A.
4) Write a function which will find the standard error of a vector, and test that it works.
26