Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Aaron Erhardt
Cheatsheets
Commits
a49c8a66
Commit
a49c8a66
authored
Apr 26, 2021
by
Aaron Erhardt
Browse files
Improve build script
Signed-off-by:
Aaron Erhardt
<
aaron.erhardt@t-online.de
>
parent
79e0e21b
Pipeline
#444
passed with stage
in 1 minute and 34 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Matlab/Matlab.md
View file @
a49c8a66
...
...
@@ -4,7 +4,7 @@
### Generate
+
Manual
Manual
```
matlab
A
=
[
1
2
3
;
4
5
6
]
...
...
@@ -14,82 +14,82 @@ A =
4
5
6
```
+
Zero
Zero
```
matlab
A
=
zeros
(
3
)
% 3x3
A
=
zeros
(
3
)
% 3x3
B
=
zeros
(
3
,
2
)
% 3x2
```
+
Ones
Ones
```
matlab
A
=
ones
(
3
)
% 3x3
A
=
ones
(
3
)
% 3x3
B
=
ones
(
3
,
2
)
% 3x2
```
+
Eye (zeros with ones in the diagonal)
Eye (zeros with ones in the diagonal)
```
matlab
A
=
eye
(
3
)
% 3x3
A
=
eye
(
3
)
% 3x3
B
=
eye
(
3
,
2
)
% 3x2
```
+
Magic
Magic
```
matlab
A
=
magic
(
3
)
% 3x3
```
+
Random values (from 0 to 1)
Random values (from 0 to 1)
```
matlab
A
=
rand
(
3
)
.*
2
% 3x3 with values from 0 to 2
B
=
rand
(
3
,
2
)
% 3x2
B
=
rand
(
3
,
2
)
% 3x2
```
+
Normally distributed random values (σ = 1, µ = 0)
Normally distributed random values (σ = 1, µ = 0)
```
matlab
A
=
randn
(
3
)
.*
2
% 3x3 with σ = 2, µ = 0
B
=
randn
(
3
,
2
)
% 3x2
A
=
randn
(
3
)
.*
2
% 3x3 with σ = 2, µ = 0
B
=
randn
(
3
,
2
)
% 3x2
C
=
randn
(
3
,
2
)
+
3
% 3x2 with σ = 1, µ = 3
```
### Modify
+
Transpose
Transpose
```
matlab
T
=
A
'
```
+
Invert
Invert
```
matlab
B
=
inv
(
A
)
```
+
Rotate
Rotate
```
matlab
B
=
rot90
(
A
)
```
+
Flip
Flip
```
matlab
B
=
flip
(
A
)
% flip rows (top to bottom)
B
=
flip
(
A
)
% flip rows (top to bottom)
B
=
fliplr
(
A
)
% flip columns (left to right)
```
+
Multiply
Multiply
```
matlab
C
=
A
*
B
```
+
Element wise multiplication
Element wise multiplication
```
matlab
C
=
A
.*
B
...
...
@@ -97,28 +97,28 @@ C = A .* B
### Access
+
As row vector
As row vector
```
matlab
A
(:)
```
+
Get rows
Get rows
```
matlab
A
(
1
,
:)
% row 1
```
+
Get columns
Get columns
```
matlab
A
(:,
1
)
% column 1
```
+
Get diagonal
Get diagonal
```
matlab
diag
(
A
)
% main diagonal (top left to bottom right)
diag
(
A
)
% main diagonal (top left to bottom right)
diag
(
flip
(
A
))
% other diagonal (bottom left to top right)
```
...
...
@@ -130,7 +130,7 @@ x = A \ b % solves Ax = b
### Visualize
+
Histogram
Histogram
```
matlab
histogram
(
A
)
...
...
@@ -138,19 +138,19 @@ histogram(A)
## Images
+
Load image
Load image
```
matlab
img
=
imread
(
'path_to_file'
)
```
+
Show image
Show image
```
matlab
imagesc
(
img
)
```
+
Color map
Color map
```
matlab
colormap
(
gray
())
% gray color map
...
...
@@ -159,14 +159,14 @@ colormap(M) % where M 255x3 with values from 0 to 1
## Strings
+
Create
Create
```
matlab
str
=
"Hello"
fromChar
=
string
(
text
)
```
+
Concatenate
Concatenate
```
matlab
str2
=
str
+
" World!"
...
...
@@ -174,20 +174,20 @@ str2 = str + " World!"
## Character array
+
Create
Create
```
matlab
text
=
'Hello'
fromStr
=
char
(
str
)
```
+
Concatenate
Concatenate
```
matlab
text2
=
[
text
' World!'
]
```
+
Access characters
Access characters
```
matlab
c
=
text
(
1
)
% first character
...
...
@@ -195,7 +195,7 @@ c = text(1) % first character
### Convert
+
string to number
string to number
```
matlab
str2num
(
'2'
)
...
...
@@ -203,19 +203,19 @@ str2num('2')
## Output
+
Create formatted string
Create formatted string
```
matlab
sprintf
(
'value: %f'
,
float_val
)
```
+
Print string
Print string
```
matlab
disp
(
'Hello'
)
```
+
Print formatted string
Print formatted string
```
matlab
% use \n for newline, the 1 is for printing to stdout
...
...
@@ -227,7 +227,7 @@ fprintf(1, 'value: %d\n', 2)
## Structs
+
Create struct, add fields and access fields
Create struct, add fields and access fields
```
matlab
student
.
name
=
"TestStudent"
% create
...
...
@@ -240,19 +240,19 @@ disp(student.name) % print name
Array containing different data types
+
Create
Create
```
matlab
ca
=
{
'chars'
,
9.81
,
1
}
% 1x3 cell array
```
+
Access elements
Access elements
```
matlab
ca
(
1
)
% -> 'chars'
```
+
Length
Length
```
matlab
length
(
ca
)
...
...
@@ -260,26 +260,26 @@ length(ca)
## Table
+
Properties
Properties
```
matlab
table
.
Properties
table
.
Properties
.
VariableNames
{
1
}
% first column name
```
+
Access column by name
Access column by name
```
matlab
table
.
column_name
% access column (as vector) with name "column_name"
```
+
Get sub-table
Get sub-table
```
matlab
table
(:,
2
)
% second column as table
```
+
Access values
Access values
```
matlab
table
{
1
,
2
}
% row 1, column 2, note brackets!
...
...
@@ -291,7 +291,7 @@ table{:, 2} % column 2
## Workspace
+
Save and load
Save and load
```
matlab
save
file_name
...
...
@@ -300,7 +300,7 @@ load file_name
## Table
+
Load
Load
```
matlab
table
=
readtable
(
'file_name'
)
...
...
@@ -397,7 +397,7 @@ plot(...)
### Formatting
+
Markers
Markers
```
matlab
plot
(
x
,
y
,
'.r'
);
% red dots
...
...
@@ -406,7 +406,7 @@ plot(x, y, 'xr'); % red x
plot
(
x
,
y
,
'*r'
);
% red stars
```
+
Lines
Lines
```
matlab
plot
(
x
,
y
,
'-'
);
% regular lines
...
...
@@ -415,25 +415,25 @@ plot(x, y, '--'); % dashed lines
plot
(
x
,
y
,
'-.'
);
% dashed and dotted lines
```
+
Colors
Colors
```
matlab
plot
(
x
,
y
,
'color'
,
[
0
,
0.6
,
0.2
]);
% RGB color
```
+
Line width
Line width
```
matlab
plot
(
x
,
y
,
'LineWidth'
,
2
);
% set line width to 2 px
```
+
Marker color
Marker color
```
matlab
plot
(
x
,
y
,
'MarkerFaceColor'
,
[
0
,
0.6
,
0.2
]);
% RGB color of markers
```
+
Marker size
Marker size
```
matlab
plot
(
x
,
y
,
'MarkerSize'
,
7
);
% set marker size to 7 px
...
...
@@ -553,7 +553,7 @@ else
end
```
+
Comparing vectors
Comparing vectors
```
matlab
vec1
=
[
1
2
3
];
...
...
build.sh
View file @
a49c8a66
...
...
@@ -5,12 +5,17 @@ build_pdf() {
-f
markdown
\
-V
geometry:a4paper
\
-V
geometry:margin
=
2cm
\
-V
mainfont
=
'
DejaVuSans
'
\
-V
mainfont
=
'
Ubuntu
'
\
-V
monofont
=
'DejaVuSansMono'
\
-V
documentclass
=
"article"
\
-V
fontsize
=
"1
1
pt"
\
-V
fontsize
=
"1
2
pt"
\
-V
linkcolor:blue
\
-V
smart
\
-H
../header.tex
\
--standalone
\
--highlight
=
tango
\
--pdf-engine
=
xelatex
\
--toc
\
-o
"../pdf/
$1
.pdf"
}
...
...
header.tex
0 → 100644
View file @
a49c8a66
\usepackage
[all]
{
nowidow
}
\widowpenalty
10000
\clubpenalty
1000
\widowpenalty
10000
\clubpenalty
100000
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment