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
32a69b36
Commit
32a69b36
authored
Jun 23, 2021
by
Aaron Erhardt
Browse files
Final update for Matlab cheatsheet
Signed-off-by:
Aaron Erhardt
<
aaron.erhardt@t-online.de
>
parent
1313c56c
Pipeline
#756
passed with stage
in 1 minute and 59 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Matlab/Matlab.md
View file @
32a69b36
...
...
@@ -126,6 +126,13 @@ diag(flip(A)) % other diagonal (bottom left to top right)
x
=
A
\
b
% solves Ax = b
```
## Find indices
```
matlab
i
=
find
(
A
);
% find all nonzero elements
i
=
find
(
A
>
1
);
i
=
find
(
A
<
1
,
5
);
% get the first five elements
```
# Images
...
...
@@ -134,14 +141,14 @@ x = A \ b % solves Ax = b
```
matlab
img
=
imread
(
'path_to_file'
)
```
###
Show image
###
Show image
```
matlab
imagesc
(
img
)
```
Color map
###
Color map
```
matlab
colormap
(
gray
())
% gray color map
...
...
@@ -283,6 +290,7 @@ fprintf(1, 'value: %d\n', 2)
```
matlab
save
file_name
save
file_name
a
b
c
% only save a, b and c
load
file_name
```
...
...
@@ -309,6 +317,12 @@ fclose(file_handle)
# Polynomials
## Create polynomial from roots
```
matlab
p
=
poly
([
1
-
2
3
]);
```
## Fit polynomial to points
```
matlab
...
...
@@ -323,6 +337,17 @@ p = polyfit(x, y, deg);
y
=
polyval
(
p
,
x
);
```
## Multiply polynomials
```
matlab
p3
=
conv
(
p1
,
p2
);
```
## Get roots
```
matlab
r
=
roots
(
p
);
```
# Graphics
...
...
@@ -689,12 +714,39 @@ opts = odeset('absTol', 0.05); % set absolute error tolerance
[
t
y
]
=
ode45
(
@
pendfun
,
tspan
,
yNull
,
opts
);
```
### Other solving algorithms
# Transfer functions
## Create
```
matlab
ode23s
%
G
=
tf
([
1
0
],
[
2
0
0
]);
```
## Step response information
```
matlab
S
=
stepinfo
(
G
);
```
## Plot step response
```
matlab
orstep
(
G
);
step
(
G
,
0.2
);
```
## Plot bode diagram
```
matlab
bode
(
G
);
```
## Plot nyquist diagram
```
matlab
nyquist
(
G
);
```
# Control structures
...
...
@@ -802,4 +854,4 @@ for i = x
y
(
cnt
)
=
sin
(
i
);
cnt
=
cnt
+
1
;
end
```
```
\ No newline at end of file
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