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
e004daca
Commit
e004daca
authored
Apr 26, 2021
by
Aaron Erhardt
Browse files
Matlab lecture 26.4
Signed-off-by:
Aaron Erhardt
<
aaron.erhardt@t-online.de
>
parent
20d90fd2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Matlab/Matlab.md
View file @
e004daca
...
...
@@ -222,6 +222,7 @@ disp('Hello')
fprintf
(
1
,
'value: %d\n'
,
2
)
```
# Datatypes
## Structs
...
...
@@ -285,6 +286,7 @@ table{1, 2} % row 1, column 2, note brackets!
table
{:,
2
}
% column 2
```
# Save and load
## Workspace
...
...
@@ -338,7 +340,9 @@ y = polyval(p, x);
# Graphics
## Plot
## Plots
### Plot
```
matlab
x
=
1
:
10
;
...
...
@@ -347,6 +351,43 @@ plot(y); % automatic x-axis
plot
(
x
,
y
);
% custom x-axis
```
### Stairs plot
```
matlab
stairs
(
x
,
y
);
% plot values as stairs
```
### Discrete values
```
matlab
ffty
=
fft
(
y
);
% fast-fourier transform
stem
(
x
,
abs
(
ffty
));
% plot FFT
```
### Logarithmic
```
matlab
loglog
(
x
,
y
);
% both axes are logarithmic
```
### Semi-logarithmic
```
matlab
semilogx
(
x
,
y
);
% x-axes is logarithmic, y-axis is linear
semilogy
(
x
,
y
);
% x-axes is linear, y-axis is logarithmic
```
## Charts
### Bar
```
matlab
h
=
bar
([
1
2
4
8
]);
% create bar chart
h
.
FaceColor
=
[
0
,
0.7
0
];
% set properties
```
## Plot options
### Hold (keep previous plots)
```
matlab
...
...
@@ -417,12 +458,68 @@ xlabel('\alpha'); % set x-label to α
ylabel
(
'y'
);
```
### Axes
```
matlab
axis
([
XMIN
XMAX
YMIN
YMAX
]);
% set scaling of both axes
```
## Figures
```
matlab
fig
=
figure
fig
=
figure
;
% note: properties are case sensitive!
fig
=
gcf
;
% get handle to current figure
```
### Typical object hierarchy
```
mermaid
graph Structure;
Figure-->Legend;
Figure-->Axes;
Axes-->Lines;
```
### Set color
```
matlab
fig
.
Color
=
'w'
;
% white
fig
.
Color
=
[
1.0
0.5
0.0
];
% RGB
```
### Plot handles
```
matlab
h
=
plot
(
x
,
y
);
% get handle
h
.
LineWidth
=
1.3
;
% modify properties
h
.
Marker
=
'.'
;
% set marker
```
### Sub-plots
```
matlab
fig
=
figure
;
subplot
(
2
,
3
,
1
);
% 2x3 matrix of plots, select first plot
plot
(
x
,
y
);
% first plot
subplot
(
2
,
3
,
2
);
% 2x3 matrix of plots, select second plot
loglog
(
x
,
y
);
% second plot
subplot
(
2
,
3
,
4
);
% 2x3 matrix of plots, select fourth plot
semilogx
(
x
,
y
);
% second row, first plot
subplot
(
2
,
3
,
6
);
% 2x3 matrix of plots, select last plot
semilogy
(
x
,
y
);
% second row, third plot
```
Get handle
```
matlab
handle
=
subplot
(
2
,
3
,
1
);
% select first plot
handle
.
Children
(
1
)
.
LineWidth
=
2
;
% get line from handle and change width
```
# Control structures
## for-loop
...
...
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