Matlab course - Program

23
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

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

Transcript of Matlab course - Program

Page 1: Matlab course - Program

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

Page 2: Matlab course - Program

Matlab course - introduction

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

• Hands on

Page 3: Matlab course - Program

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

Page 4: Matlab course - Program

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)

Page 5: Matlab course - Program
Page 6: Matlab course - Program

Visualizing data

Page 7: Matlab course - Program

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

Page 8: Matlab course - Program

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

Page 9: Matlab course - Program

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

Page 10: Matlab course - Program
Page 11: Matlab course - Program

Images=matrices

10 20 30 40 50 60 70 80 90

10

20

30

40

50

60

70

80

90

100

Page 12: Matlab course - Program

Imagescaling

Min value Max value

Full range

Partial range

Page 13: Matlab course - Program

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])

Page 14: Matlab course - Program

Loading a dicom file

• Matrix=dicomread(’filename’);

• Matrix=double(Matrix);

• imagesc(Matrix)

Page 15: Matlab course - Program

colormap(cmap_name)

50 100 150 200 250

50

100

150

200

250

Page 16: Matlab course - Program

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

Page 17: Matlab course - Program

Logical comparisons

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

50 100 150 200 250

50

100

150

200

250

Page 18: Matlab course - Program

Roipoly – will return a mask

50 100 150 200 250

50

100

150

200

250

Page 19: Matlab course - Program

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

Page 20: Matlab course - Program

Birgitte – how do we do stats on a mask?

Page 21: Matlab course - Program

Exercise

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

• Plot a histogram of your ROI

Page 22: Matlab course - Program

Saving work

• save workspacename

• save filename X saves only X.

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

Page 23: Matlab course - Program

The online docs

• Very usefull

• Good links

• Good newsgroup

• Tomorrow: structures – the dir command