-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.DataTypes.m
More file actions
109 lines (90 loc) · 1.41 KB
/
3.DataTypes.m
File metadata and controls
109 lines (90 loc) · 1.41 KB
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
%% 3. Data Types
% Numeric Type
x = 5
class(x)
whos x
class(x)
y = single(5)
class(y)
whos x
whos y
realmin('single')
realmax('double')
z = uint64(5)
whos z
% Inf, NaN and Other Constants
1/0
inf
isinf(ans)
whos inf
inf
whos ans
0/0
inf/inf
isnan(ans)
pi
whos pi
pi
whos ans
format rat
pi
format longg
i
j
sqrt(-5:5)
i
whos ans
% Numeric Output Formats
10^10
format longg
ans
format bank
pi
format hex
123
format rat
2*3/7+1/12
pi/2
format
% Character Strings
s = 'hello'
'let''s go'
whos s
s(1)
whos ans
a = 'hello'
b = 'world'
[a ', ' b '!'] % string concatenation
age = 30
['I am ' num2str(age) ' years old'] % convert numeric to string
disp(ans)
dsolve('Dq = q*r', 'q(0) = q0', 't') % pass to toolbox as string for evaluation
strcmpi('ABC', 'abc') % compare two strings (case insensitive)
% Structures
person.name = 'john'
person.age = 22
person.age
person.name
whos person
address.housename = 123
address.streetname = 'london road'
person.address = address
% Cell Arrays
x = 42
whos x
x(2) = 24
whos x
address = {123, 'london road'}
person = {'john', 22, address}
whos person
person(1)
whos ans
person{1}
whos ans
% Function Handles
s = @sin
s(pi / 2)
sumOver3 = @(x, y) (x + y) / 3
sumOver3(1, 2)
incApply = @(x, y, f) f(x + 1, y + 1)
incApply(2, 3, sumOver3)