Matlab Class 8 Xiaotao Su, Ph.D. Visual Psychophysicist - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Matlab Class 8 Xiaotao Su, Ph.D. Visual Psychophysicist

Description:

Matlab Class 8 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 15
Provided by: Robert1948
Category:

less

Transcript and Presenter's Notes

Title: Matlab Class 8 Xiaotao Su, Ph.D. Visual Psychophysicist


1
Matlab Class 8Xiaotao Su, Ph.D.Visual
Psychophysicist IT Group LeaderRutgers Center
for Cognitive Science (RuCCS)andChris Kourtev
2
Small Pieces
  • Starting with matlab version 7.0 you can execute
    small chunks of code
  • This is called cells (nothing to do with cell
    arrays)
  • mark off the beginning and end of cell region
  • Cell regions are seen as yellow
  • Pressing ctrl/cmd return causes the workspace
    to execute the command in the active cell

If you do not see a yellow region, in the
menu bar select Cell-gtEnable Cell Mode
3
Creating a vector of numbers
  • This is similar to the way you create an
    iteration for a for loop
  • x (020) ----gt x 0, 1, 20
  • x (0.10.11) ---gt x 0.1, 0.2, , 1.0
  • x (0220) ----gt x 0, 2, 4, 20
  • x (0220) ---gt vertical vector like the
    previous one

4
discrete distributions and selecting segments
  • you can use something like x(020) to specify a
    discrete distribution of 21 different
    possibilities
  • to select the first 6 elements you could sayy
    x(16) ---gt y would be 0, 1 5
  • Or to select the last 4 elements
  • y x(end-3end) ---gt y would be 17, 18, 19, 20

5
y binopdf(x(16), 5, .8)
  • used to generate a binomial distribution function
    the case in which one flips a weighted coin
  • .8 probability of getting heads
  • there are 6 possibilities (0 heads, 1 head 5
    heads
  • y gives the probability of each of these outcomes

This function requires the stats toolbox
6
Plotting
  • Subplot will create a figure window for plotting
  • subplot (2, 1, 2) will say we are going to create
    a (2 row, 1 column, ) figure. The last number
    specifies that we are currently going to write in
    the second element of this figure.
  • plot(y) will create a graph on currently chosen
    section of the figure (specified by the third
    parameter in subplot)

7
setting up the plot
  • xlim(1 5) sets the limits of the x axis
  • bar(y) will use a bar graph
  • ylabel(Probability of n)
  • xlabel(N)
  • title(Discrete distributions should be plotted
    as histograms)

8
more then one figure?
  • figure opens a new figure window
  • All new subplots will go to the new figure
  • subplot(2, 1, 1)
  • bar(y)
  • xlim(1 21) we want 21 possibilities

9
more then one graph on a plot
  • hold on tells matlab to keep the previous graph
    and draw a new one on top
  • stairs(cumsum(y), r)
  • cumsum(y) lt--- each value is the sum of previous
    values of y
  • r makes the graph line red
  • stairs will plot it as a staircase
  • hold off now any future graph additions will
    clear previous graphs on this plot
  • legend(distribution, cumsum)

10
Using images in experiments
  • Images are stored in matlab as
  • Width x Height x 3 matrix

x
R
G
y
B




11
file -gt matrix and drawing it on the screen
  • img imread(winter.jpg, jpg)
  • You draw an image just like you would a
    rectangle
  • Screen(window, PutImage, img, 0, 0, 200,
    200)

12
Image info and structures
  • img_info imfinfo(winter.jpg)
  • img_info.Width will be the width of the image
  • screen(window, PutImage, img,
  • 0, 0, img_info.Width, img_info.Height)

13
Making sounds
  • A sound is a 2 x N matrix where N is the number
    of bits that make up the sound file and the two
    channels are for left and right

14
Making sounds
  • sound, samplerate, samplesize
  • wavread(feedback.wav)
  • sound sound
  • Snd(Play, sound, samplerate, samplesize)

Tip To make your own wav files I recommend
using an application called audacity http//audac
ity.sourceforge.net/
Write a Comment
User Comments (0)
About PowerShow.com