Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 2/Octave Tutorial/2. Moving Data Around/moving_data_around.txt
625 views
1
octave:2> A = [ 1 2; 3 4; 5 6]
2
A =
3
4
1 2
5
3 4
6
5 6
7
8
octave:3> x = size(A);
9
octave:4> x
10
x =
11
12
3 2
13
14
octave:5> size(x)
15
ans =
16
17
1 2
18
19
octave:6> size(A,1)
20
ans = 3
21
octave:7> size(A,2)
22
ans = 2
23
octave:8> pwd
24
ans = C:\Users\amlan
25
octave:9> cd 'C:\Users\amlan\Documents\Git Repos\Machine Learning\Coursera_ML_Andrew\Octave Tutorial\Moving Data Around'
26
octave:10> ls
27
Volume in drive C has no label.
28
Volume Serial Number is FA5E-CC30
29
30
Directory of C:\Users\amlan\Documents\Git Repos\Machine Learning\Coursera_ML_Andrew\Octave Tutorial\Moving Data Around
31
32
[.] [..]
33
0 File(s) 0 bytes
34
2 Dir(s) 173,247,627,264 bytes free
35
octave:11> ls
36
Volume in drive C has no label.
37
Volume Serial Number is FA5E-CC30
38
39
Directory of C:\Users\amlan\Documents\Git Repos\Machine Learning\Coursera_ML_Andrew\Octave Tutorial\Moving Data Around
40
41
[.] [..] featuresX.dat priceY.dat
42
2 File(s) 150 bytes
43
2 Dir(s) 173,247,623,168 bytes free
44
octave:12> load featuresX.dat
45
octave:13> load pri
46
priceY.dat print print_struct_array_contents printd prism
47
primes print_empty_dimensions print_usage printf
48
octave:13> load priceY.dat
49
octave:14> who
50
Variables in the current scope:
51
52
A ans featuresX priceY x
53
54
octave:15> featuresX
55
featuresX =
56
57
2103 2
58
2204 2
59
2205 2
60
3500 3
61
1450 1
62
2100 1
63
4000 3
64
4400 3
65
2800 2
66
5000 4
67
3400 2
68
69
octave:16> size(featuresX)
70
ans =
71
72
11 2
73
74
octave:17> size(priceY)
75
ans =
76
77
11 1
78
79
octave:18> whos
80
Variables in the current scope:
81
82
Attr Name Size Bytes Class
83
==== ==== ==== ===== =====
84
A 3x2 48 double
85
ans 1x2 16 double
86
featuresX 11x2 176 double
87
priceY 11x1 88 double
88
x 1x2 16 double
89
90
Total is 43 elements using 344 bytes
91
92
octave:19> v = priceY(1:5)
93
v =
94
95
2200
96
4400
97
2300
98
3000
99
4500
100
101
octave:20> save hello.mat
102
octave:21> save hello.mat v
103
octave:22> save hello.txt v -ascii #saves in ascii format
104
octave:23> A = [1 2; 3 4; 5 6]
105
A =
106
107
1 2
108
3 4
109
5 6
110
111
octave:24> % A 2
112
octave:24> A (3,2)
113
ans = 6
114
octave:25> A(2,:)
115
ans =
116
117
3 4
118
119
octave:26> A(:,2)
120
ans =
121
122
2
123
4
124
6
125
126
octave:27> A ([1 3], :)
127
ans =
128
129
1 2
130
5 6
131
132
octave:28> A(:,2) = [10; 11; 12] #Assigning values to 2nd col
133
A =
134
135
1 10
136
3 11
137
5 12
138
139
octave:29> A(:) #put all elements of A into a single vector
140
ans =
141
142
1
143
3
144
5
145
10
146
11
147
12
148
149
octave:30> B = [20 21; 22 23; 24 25]
150
B =
151
152
20 21
153
22 23
154
24 25
155
156
octave:31> C = [A B]
157
C =
158
159
1 10 20 21
160
3 11 22 23
161
5 12 24 25
162
163
octave:32> C = [A; B]
164
C =
165
166
1 10
167
3 11
168
5 12
169
20 21
170
22 23
171
24 25
172