Matlab course - Program
-
Upload
caldwell-morton -
Category
Documents
-
view
97 -
download
0
description
Transcript of Matlab course - Program
![Page 1: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/1.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/2.jpg)
Matlab course - introduction
• Goals – Visualize data– Develop programs– GUIs– Read other peoples programs (eg. SPM)
• Hands on
![Page 3: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/5.jpg)
![Page 6: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/6.jpg)
Visualizing data
![Page 7: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/7.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/8.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/10.jpg)
![Page 11: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/12.jpg)
Imagescaling
Min value Max value
Full range
Partial range
![Page 13: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/13.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/14.jpg)
Loading a dicom file
• Matrix=dicomread(’filename’);
• Matrix=double(Matrix);
• imagesc(Matrix)
![Page 15: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/15.jpg)
colormap(cmap_name)
50 100 150 200 250
50
100
150
200
250
![Page 16: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/16.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/17.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/18.jpg)
Roipoly – will return a mask
50 100 150 200 250
50
100
150
200
250
![Page 19: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/19.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/20.jpg)
Birgitte – how do we do stats on a mask?
![Page 21: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/21.jpg)
Exercise
• Use mean() to get a mean of an ROI selected using roipoly
• Plot a histogram of your ROI
![Page 22: Matlab course - Program](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/22.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022062217/56812a8e550346895d8e3a1d/html5/thumbnails/23.jpg)
The online docs
• Very usefull
• Good links
• Good newsgroup
• Tomorrow: structures – the dir command