summaryrefslogtreecommitdiff
path: root/matlab_usage_source/index.t2t
blob: 7ec51aaae919fe6b3767f36a768a10fb6ddcdb68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Matlab usage - short (may be too short) introduction



%!style(html): ../evmik.css


= How to make a simple plot =
Suppose during the measurements we obtain the following data
fir each parameter 'I' we measured 'V' with a particular uncertainty  dV.
Our data is represented in the following table.

|| I   | V   | dV  |
|  .1  | 1.0 | 0.2 |
|  1.0 | 2.2 | 0.1 |
|  1.8 | 3.2 | 0.2 |
|  3.3 | 3.8 | 0.2 |
|  4.0 | 4.9 | 0.3 |

First of all,  we need to transfer  it to the Matlab  vector variables. Pay
attention to the delimiter **;** between numbers

``` 
I  = [  .1; 1.0; 1.8; 3.3; 4.0 ]
V  = [ 1.0; 2.2; 3.2; 3.8; 4.9 ]
dV = [ 0.2; 0.1; 0.2; 0.2; 0.3 ]
```

Now we make a simple plot without error bars to get  the basic, text after
**%** is considered as a comment and matlab will disregard it.

```
figure(1) % all plotting output will go to the particular window
plot(I,V) 
```

Easy, is not it?

[simple_labeled_plot.png]


But  **every plot  must be  present with  title, proper  axes labels  and units**.
Note **'** for the string specifiers


No our plot is nice and pretty.

[simple_unlabeled_plot.png]

= Fixing the range of the axes =

Have a look at above plot. We see that one of the axes (y) does not contain
origin point  (y=0). Such plots are  very common in finances  and design to
fool a reader, but they are  generally not acceptable in scientific reports
and  definitely not  in  my class  unless  you  have a  good  reason to  do
otherwise.

The fix is very easy. Note that we are actually sending a vector [0,5] to the
**``ylim``** function (fir x-axis we need to use **``xlim``** function).
``` ylim([0,5])

Now our plot is good to present

[simple_labeled_and_proper_limits_plot.png]


= Plotting with error bars =
Let's open a new window for the plot

``` figure(2)

Now we make plot with error bars assuming that they are the same for up and down parts

``` errorbar(I,V,dV)

Yet again we need proper labeling

``` 
title('Dependence of voltage on current')
xlabel('Voltage (V)')
ylabel('Current (A)')
``` 

[errorbar_plot.png]

= Fixing plots font size =

Honestly Matlab is not the best tool to do presentation quality plots, it requires a quite a bit of messing with their GUI. But at least for quick font size fix do the following. This looks a bit like magic spell. 
```
fontSize=24;
set(gca,'FontSize',fontSize );

errorbar(I,V,dV)
title('Dependence of voltage on current')
xlabel('Voltage (V)')
ylabel('Current (A)')
```

[errorbar_with_large_font_plot.png]


= Saving you matlab plots =

Well it nice to have matlab  plots.  But as soon as you close matlab they will go away.
How to save them for a future use? Actually, quite easy.
For png output do
``` print('V_vs_I.png')

or if you need a pdf (matlab usually make very bad pdfs)
``` print('V_vs_I.pdf')

Make sure that you read documentation for **``print``** command there are some useful parameters.