Matlab course - Program

Preview:

DESCRIPTION

Matlab course - Program. Today Basic matrix operations Basic visualization. Images and plots Thursday Programming, scripts, more visualization Friday Graphical user interfaces and advanced visualizaton Any suggestions wellcome, only today is fairly set. Matlab course - introduction. - PowerPoint PPT Presentation

Citation preview

Matlab course - Program

• Today– Basic matrix operations– Basic visualization. Images and plots

• Thursday– Programming, scripts, more visualization

• Friday– Graphical user interfaces and advanced visualizaton

• Any suggestions wellcome, only today is fairly set

Matlab course - introduction

• Goals – Visualize data– Develop programs– GUIs– Read other peoples programs (eg. SPM)

• Hands on

Matlab as a language

• Vector/matrix based

• Many built in functions– Few lines of code will get you far– Extensive visualization capabilities

• Might run slower depending on task

Lets start

• Manipulating matrices and vectors– Basically needed for all programming tasks

everything

• Basic operations– Add noise to a simulated signal – an example

(hemodynamic response function)

Visualizing data

Plotting data

• The plot function– plot(y)– plot(x,y)

• X and Y can be matrices– plot() will plot the columns

• Use hold on to keep the old plot

Simulating the HRF

0

0

!

1

0)(

tt

ttth tn

et

n

Buxton: Introduction to FMRI

hrtvectortor = hrt(timevector, tau, t0, n)

0 2 4 6 8 10 12 14 16 18 200

0.02

0.04

0.06

0.08

0.1

0.12

0.14

0.16

0.18

0.2

0 2 4 6 8 10 12 14 16 18 20-0.05

0

0.05

0.1

0.15

0.2

Excercise• Part 1

– Generate a timevector, L=10 s, interval=0.1 s– Use the hrf() function to generate a hemodynamic response– Use plot to verify the output

• Part 2– Imagine that you want to display 3 different hrf functions in a plot.

Generate 3 functions and put them in a matrix columnwise. Use a single call to plot to view them

• Part 3– Use randn() to add noise to the curves. Use a std of XX– Plot again

Example hrf parameters:

timevec: from 0 to 20 secs

tau: 1.2

t0: 4 s

n: 3

Example noise parameters:

Use a std of 0.1 – 0.3 - 0.5

Images=matrices

10 20 30 40 50 60 70 80 90

10

20

30

40

50

60

70

80

90

100

Imagescaling

Min value Max value

Full range

Partial range

imagesc() + colorbar

50 100 150 200 250

50

100

150

200

2500

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

imagesc(data)

50 100 150 200 250

50

100

150

200

2500

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

imagesc(data,[0 5000])

Loading a dicom file

• Matrix=dicomread(’filename’);

• Matrix=double(Matrix);

• imagesc(Matrix)

colormap(cmap_name)

50 100 150 200 250

50

100

150

200

250

hist(data(:),[bins])

0 500 1000 1500 2000 2500 3000 3500 4000

0

500

1000

1500

2000

2500

3000

3500

50 100 150 200 250

50

100

150

200

2500

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

Logical comparisons

• Largevalues=matrix > 500– Can be true or false, 0 or 1

50 100 150 200 250

50

100

150

200

250

Roipoly – will return a mask

50 100 150 200 250

50

100

150

200

250

Exercise

• Load a dicom into a matrix

• Use hist()( to identify noise and see if there is ghosting using imagesc()

• ’Cut away’ the noise– Hint: use a comparison to make a noise mask

and then .*

• Use roipoly to mask away 1 hemisphere

Birgitte – how do we do stats on a mask?

Exercise

• Use mean() to get a mean of an ROI selected using roipoly

• Plot a histogram of your ROI

Saving work

• save workspacename

• save filename X saves only X.

• Save filenename X Y Z saves X, Y, and Z.

The online docs

• Very usefull

• Good links

• Good newsgroup

• Tomorrow: structures – the dir command

Recommended