uploaded all materials
This commit is contained in:
57
lessons/lesson03/matlab_logo.m
Normal file
57
lessons/lesson03/matlab_logo.m
Normal file
@ -0,0 +1,57 @@
|
||||
%% Creating the MATLAB logo
|
||||
% from https://www.mathworks.com/help/matlab/visualize/creating-the-matlab-logo.html
|
||||
% Copyright (C) 2014 Mathworks Inc.
|
||||
close all; clear; clc;
|
||||
|
||||
%% Create the surface
|
||||
L = 160*membrane(1,100);
|
||||
|
||||
%% Create the figure and axes
|
||||
f = figure;
|
||||
ax = axes;
|
||||
|
||||
s = surface(L);
|
||||
s.EdgeColor = 'none';
|
||||
view(3)
|
||||
|
||||
%% Adjust axis limits
|
||||
ax.XLim = [1 201];
|
||||
ax.YLim = [1 201];
|
||||
ax.ZLim = [-53.4 160];
|
||||
|
||||
%% Adjust the camera position
|
||||
ax.CameraPosition = [-145.5 -229.7 283.6];
|
||||
ax.CameraTarget = [77.4 60.2 63.9];
|
||||
ax.CameraUpVector = [0 0 1];
|
||||
ax.CameraViewAngle = 36.7;
|
||||
|
||||
%% Adjust the position of the x, y, z axes themselves
|
||||
ax.Position = [0 0 1 1];
|
||||
ax.DataAspectRatio = [1 1 .9];
|
||||
|
||||
%% Add some light
|
||||
l1 = light;
|
||||
l1.Position = [160 400 80];
|
||||
l1.Style = 'local';
|
||||
l1.Color = [0 0.8 0.8];
|
||||
|
||||
l2 = light;
|
||||
l2.Position = [.5 -1 .4];
|
||||
l2.Color = [0.8 0.8 0];
|
||||
|
||||
%% Change the surface color
|
||||
s.FaceColor = [0.9 0.2 0.2];
|
||||
|
||||
%% Adjust lighting algorithm
|
||||
s.FaceLighting = 'gouraud';
|
||||
s.AmbientStrength = 0.3;
|
||||
s.DiffuseStrength = 0.6;
|
||||
s.BackFaceLighting = 'lit';
|
||||
|
||||
s.SpecularStrength = 1;
|
||||
s.SpecularColorReflectance = 1;
|
||||
s.SpecularExponent = 7;
|
||||
|
||||
%% Remove background
|
||||
axis off
|
||||
f.Color = 'black';
|
711
lessons/lesson03/octave-log.txt
Normal file
711
lessons/lesson03/octave-log.txt
Normal file
@ -0,0 +1,711 @@
|
||||
octave:2>
|
||||
octave:2>
|
||||
octave:2>
|
||||
octave:16>
|
||||
|
||||
y2 = x.^2;^[[201~octave:16>
|
||||
octave:16>
|
||||
octave:16>
|
||||
octave:16>
|
||||
octave:16> x = -10:0.1:10;
|
||||
y = x.^3;
|
||||
y2 = x.^2;
|
||||
octave:19> size(y)
|
||||
ans =
|
||||
|
||||
1 201
|
||||
|
||||
octave:20> size(x)
|
||||
ans =
|
||||
|
||||
1 201
|
||||
|
||||
octave:21> plot(x, y)
|
||||
octave:22> plot(x, y2)
|
||||
octave:23> hold on
|
||||
octave:24> plot(x, y)
|
||||
octave:25> figure
|
||||
octave:26> plot(x, y)
|
||||
octave:27> close all
|
||||
octave:28> figure
|
||||
octave:29> plot(x, y)
|
||||
octave:30> xlabel('x axis')
|
||||
octave:31> ylabel('y axis')
|
||||
octave:32> ylabel('y axis! yay!')
|
||||
octave:33> ylabel('y axis! yay! more letters')
|
||||
octave:34> title('a plot of a cubic')
|
||||
octave:35> grid on
|
||||
octave:36> legend('x^3')
|
||||
octave:37> hold on
|
||||
octave:38> close all
|
||||
octave:39>
|
||||
^[[201~octave:39>
|
||||
octave:39>
|
||||
octave:39>
|
||||
octave:39>
|
||||
octave:39> hold on; % plotting more than 1 plot on 1 figure rather than overwriting
|
||||
|
||||
|
||||
plot(x, y, 'DisplayName', 'x^3');
|
||||
plot(x, y2, 'DisplayName', 'x^2');
|
||||
|
||||
hold off;
|
||||
|
||||
xlabel 'x axis';
|
||||
ylabel 'y axis';
|
||||
title 'Example 1';
|
||||
xlim([-10 10]);
|
||||
ylim([-10 10]);
|
||||
% axis([-10 10 -10 10]);
|
||||
grid on;
|
||||
legend show; % 'DisplayName does thisi
|
||||
octave:50> close all
|
||||
octave:51> help axis
|
||||
'axis' is a function from the file /usr/share/octave/7.3.0/m/plot/appearance/axis.m
|
||||
|
||||
-- axis ()
|
||||
-- axis ([X_LO X_HI])
|
||||
-- axis ([X_LO X_HI Y_LO Y_HI])
|
||||
-- axis ([X_LO X_HI Y_LO Y_HI Z_LO Z_HI])
|
||||
-- axis ([X_LO X_HI Y_LO Y_HI Z_LO Z_HI C_LO C_HI])
|
||||
-- axis (OPTION)
|
||||
-- axis (OPTION1, OPTION2, ...)
|
||||
-- axis (HAX, ...)
|
||||
-- LIMITS = axis ()
|
||||
Set axis limits and appearance.
|
||||
|
||||
The argument LIMITS should be a 2-, 4-, 6-, or 8-element vector.
|
||||
The first and second elements specify the lower and upper limits
|
||||
for the x-axis. The third and fourth specify the limits for the
|
||||
y-axis, the fifth and sixth specify the limits for the z-axis, and
|
||||
the seventh and eighth specify the limits for the color axis. The
|
||||
special values '-Inf' and 'Inf' may be used to indicate that the
|
||||
limit should be automatically computed based on the data in the
|
||||
axes.
|
||||
|
||||
Without any arguments, 'axis' turns autoscaling on.
|
||||
|
||||
With one output argument, 'LIMITS = axis' returns the current axis
|
||||
limits.
|
||||
|
||||
The vector argument specifying limits is optional, and additional
|
||||
string arguments may be used to specify various axis properties.
|
||||
|
||||
The following options control the aspect ratio of the axes.
|
||||
|
||||
"equal"
|
||||
Force x-axis unit distance to equal y-axis (and z-axis) unit
|
||||
distance.
|
||||
|
||||
"square"
|
||||
Force a square axis aspect ratio.
|
||||
|
||||
"vis3d"
|
||||
Set aspect ratio modes ("DataAspectRatio",
|
||||
"PlotBoxAspectRatio") to "manual" for rotation without
|
||||
stretching.
|
||||
|
||||
"normal"
|
||||
"fill"
|
||||
Restore default automatically computed aspect ratios.
|
||||
|
||||
The following options control the way axis limits are interpreted.
|
||||
|
||||
"auto"
|
||||
"auto[xyz]"
|
||||
"auto [xyz]"
|
||||
Set nice auto-computed limits around the data for all axes, or
|
||||
only the specified axes.
|
||||
|
||||
"manual"
|
||||
Fix the current axes limits.
|
||||
|
||||
"tight"
|
||||
Fix axes to the limits of the data.
|
||||
|
||||
"image"
|
||||
Equivalent to "tight" and "equal".
|
||||
|
||||
The following options affect the appearance of tick marks.
|
||||
|
||||
"tic"
|
||||
"tic[xyz]"
|
||||
"tic [xyz]"
|
||||
Turn tick marks on for all axes, or turn them on for the
|
||||
specified axes and off for the remainder.
|
||||
|
||||
"label"
|
||||
"label[xyz]"
|
||||
"label [xyz]"
|
||||
Turn tick labels on for all axes, or turn them on for the
|
||||
specified axes and off for the remainder.
|
||||
|
||||
"nolabel"
|
||||
Turn tick labels off for all axes.
|
||||
|
||||
Note: If there are no tick marks for an axes then there can be no
|
||||
labels.
|
||||
|
||||
The following options affect the direction of increasing values on
|
||||
the axes.
|
||||
|
||||
"xy"
|
||||
Default y-axis, larger values are near the top.
|
||||
|
||||
"ij"
|
||||
Reverse y-axis, smaller values are near the top.
|
||||
|
||||
The following options affects the visibility of the axes.
|
||||
|
||||
"on"
|
||||
Make the axes visible.
|
||||
|
||||
"off"
|
||||
Hide the axes.
|
||||
|
||||
If the first argument HAX is an axes handle, then operate on this
|
||||
axes rather than the current axes returned by 'gca'.
|
||||
|
||||
Example 1: set X/Y limits and force a square aspect ratio
|
||||
|
||||
axis ([1, 2, 3, 4], "square");
|
||||
|
||||
Example 2: enable tick marks on all axes, enable tick mark labels
|
||||
only on the y-axis
|
||||
|
||||
axis ("tic", "labely");
|
||||
|
||||
See also: xlim, ylim, zlim, caxis, daspect, pbaspect, box, grid.
|
||||
|
||||
Additional help for built-in functions and operators is
|
||||
available in the online version of the manual. Use the command
|
||||
'doc <topic>' to search the manual index.
|
||||
|
||||
Help and information about Octave is also available on the WWW
|
||||
at https://www.octave.org and via the help@octave.org
|
||||
mailing list.
|
||||
octave:52>
|
||||
|
||||
d2 = cos(t);^[[201~octave:52>
|
||||
octave:52>
|
||||
octave:52>
|
||||
octave:52>
|
||||
octave:52> t = 0:.1:10;
|
||||
d1 = sin(t);
|
||||
d2 = cos(t);
|
||||
octave:55> figure
|
||||
octave:56>
|
||||
^[[200~hold on;
|
||||
plot(t, d1);
|
||||
plot(t, d2);
|
||||
hold off;^[[201~octave:56>
|
||||
octave:56>
|
||||
octave:56>
|
||||
octave:56>
|
||||
octave:56> hold on;
|
||||
plot(t, d1);
|
||||
plot(t, d2);
|
||||
hold off;
|
||||
octave:60>
|
||||
^[[200~title 'Trig Functions';^[[201~octave:60>
|
||||
octave:60>
|
||||
octave:60>
|
||||
octave:60>
|
||||
octave:60> title 'Trig Functions';
|
||||
octave:61>
|
||||
^[[200~xlabel 'time (\mu)s';^[[201~octave:61>
|
||||
octave:61>
|
||||
octave:61>
|
||||
octave:61>
|
||||
octave:61> xlabel('time (\mu)s');
|
||||
octave:62> ylabel('voltage')
|
||||
octave:63> legend('sin', 'cos')
|
||||
octave:64> close all
|
||||
octave:65> figure
|
||||
octave:66>
|
||||
octave:66>
|
||||
octave:66>
|
||||
octave:66>
|
||||
octave:66>
|
||||
octave:66> plot(t, d1, 'b-.', t, d2, 'rp');
|
||||
octave:67>
|
||||
|
||||
^[[200~title 'Trig Functions';
|
||||
xlabel 'time ($\mu$s)' Interpreter latex
|
||||
ylabel voltage;
|
||||
legend('sin', 'cos');
|
||||
xticks(0:pi/2:10);
|
||||
xticklabels({'0', '\pi/2', '\pi', '3\pi/2', '2\pi', '5\pi/2', '3\pi'});^[[201~octave:6
|
||||
7>
|
||||
octave:67>
|
||||
octave:67>
|
||||
octave:67>
|
||||
octave:67> title 'Trig Functions';
|
||||
xlabel 'time ($\mu$s)' Interpreter latex
|
||||
ylabel voltage;
|
||||
legend('sin', 'cos');
|
||||
xticks(0:pi/2:10);
|
||||
xticklabels({'0', '\pi/2', '\pi', '3\pi/2', '2\pi', '5\pi/2', '3\pi'});
|
||||
sh: 1: dvipng: not found
|
||||
warning: latex_renderer: a run-time test failed and the 'latex' interpreter has been d
|
||||
isabled.
|
||||
warning: called from
|
||||
__axis_label__ at line 36 column 6
|
||||
xlabel at line 59 column 8
|
||||
|
||||
octave:73> title 'Trig Functions';
|
||||
xlabel 'time ($\mu$s)' Interpreter latex
|
||||
ylabel voltage;
|
||||
legend('sin', 'cos');
|
||||
xticks(0:pi/2:10);
|
||||
xticklabels({'0', '\pi/2', '\pi', '3\pi/2',
|
||||
octave:73>
|
||||
^[[200~xticks(0:pi/2:10);^[[201~octave:73>
|
||||
octave:73>
|
||||
octave:73>
|
||||
octave:73>
|
||||
octave:73> xticks(0:pi/2:10);
|
||||
octave:74>
|
||||
^[[200~xticklabels({'0', '\pi/2', '\pi', '3\pi/2', '2\pi', '5\pi/2', '3\pi'});^[[201~o
|
||||
ctave:74>
|
||||
octave:74>
|
||||
octave:74>
|
||||
octave:74>
|
||||
octave:74> xticklabels({'0', '\pi/2', '\pi', '3\pi/2', '2\pi', '5\pi/2', '3\pi'});
|
||||
octave:75> close all
|
||||
octave:76> figure
|
||||
octave:77> subplot(2, 1, 1)
|
||||
octave:78>
|
||||
^[[200~octave:75> close all^[[201~octave:78>
|
||||
octave:78>
|
||||
octave:78>
|
||||
octave:78>
|
||||
octave:78> octave:75> close all
|
||||
octave:78> figure
|
||||
octave:79> subplot(2, 1, 1)
|
||||
octave:80> plot(t, d1)
|
||||
octave:81> hold on
|
||||
octave:82> plot(t, d2)
|
||||
octave:83> title('an ordinary plot')
|
||||
octave:84> subplot(2, 1, 2)
|
||||
octave:85>
|
||||
octave:85>
|
||||
octave:85>
|
||||
octave:85>
|
||||
octave:85>
|
||||
octave:85> plot(t, d1, 'b-.', t, d2, 'rp');
|
||||
title 'Customized plot';
|
||||
octave:87> close all
|
||||
octave:88> figure
|
||||
octave:89> stem(t, d1)
|
||||
octave:90> hold on
|
||||
octave:91> scatter(t, d2)
|
||||
octave:92> close all
|
||||
octave:93>
|
||||
^[[200~t = linspace(0,10*pi);^[[201~octave:93>
|
||||
octave:93>
|
||||
octave:93>
|
||||
octave:93>
|
||||
octave:93> t = linspace(0,10*pi);
|
||||
octave:94> figure
|
||||
octave:95> plot3(sin(t), cos(t), t)
|
||||
octave:96> zlabel('t')
|
||||
octave:97> zlabel('tttttttttttttttttttttttttttttttttttt')
|
||||
octave:98> title('a helix! in space!')
|
||||
octave:99> text(0, 0, 0, 'origin')
|
||||
octave:100> close all
|
||||
octave:101>
|
||||
^[[200~a1 = -2:0.25:2;
|
||||
b1 = a1;
|
||||
[A1, B1] = meshgrid(a1);
|
||||
F = A1.*exp(-A1.^2-B1.^2);^[[201~octave:101>
|
||||
octave:101>
|
||||
octave:101>
|
||||
octave:101>
|
||||
octave:101> a1 = -2:0.25:2;
|
||||
b1 = a1;
|
||||
[A1, B1] = meshgrid(a1);
|
||||
F = A1.*exp(-A1.^2-B1.^2);
|
||||
octave:105> A1
|
||||
A1 =
|
||||
|
||||
Columns 1 through 9:
|
||||
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
-2.0000 -1.7500 -1.5000 -1.2500 -1.0000 -0.7500 -0.5000 -0.2500 0
|
||||
|
||||
Columns 10 through 17:
|
||||
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
|
||||
|
||||
octave:106> B1
|
||||
B1 =
|
||||
|
||||
Columns 1 through 9:
|
||||
|
||||
-2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000
|
||||
-1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500
|
||||
-1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000
|
||||
-1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500
|
||||
-1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000
|
||||
-0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500
|
||||
-0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000
|
||||
-0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500
|
||||
0 0 0 0 0 0 0 0 0
|
||||
0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500
|
||||
0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000
|
||||
0.7500 0.7500 0.7500 0.7500 0.7500 0.7500 0.7500 0.7500 0.7500
|
||||
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
|
||||
1.2500 1.2500 1.2500 1.2500 1.2500 1.2500 1.2500 1.2500 1.2500
|
||||
1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000
|
||||
1.7500 1.7500 1.7500 1.7500 1.7500 1.7500 1.7500 1.7500 1.7500
|
||||
2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000
|
||||
|
||||
Columns 10 through 17:
|
||||
|
||||
-2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000
|
||||
-1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500 -1.7500
|
||||
-1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000 -1.5000
|
||||
-1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500 -1.2500
|
||||
-1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000
|
||||
-0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500 -0.7500
|
||||
-0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000
|
||||
-0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500 -0.2500
|
||||
0 0 0 0 0 0 0 0
|
||||
0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500
|
||||
0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000
|
||||
0.7500 0.7500 0.7500 0.7500 0.7500 0.7500 0.7500 0.7500
|
||||
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
|
||||
1.2500 1.2500 1.2500 1.2500 1.2500 1.2500 1.2500 1.2500
|
||||
1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000
|
||||
1.7500 1.7500 1.7500 1.7500 1.7500 1.7500 1.7500 1.7500
|
||||
2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000
|
||||
|
||||
octave:107> F
|
||||
F =
|
||||
|
||||
Columns 1 through 9:
|
||||
|
||||
-0.0007 -0.0015 -0.0029 -0.0048 -0.0067 -0.0078 -0.0071 -0.0043 0
|
||||
-0.0017 -0.0038 -0.0074 -0.0123 -0.0172 -0.0200 -0.0182 -0.0110 0
|
||||
-0.0039 -0.0086 -0.0167 -0.0276 -0.0388 -0.0450 -0.0410 -0.0248 0
|
||||
-0.0077 -0.0172 -0.0331 -0.0549 -0.0771 -0.0896 -0.0816 -0.0492 0
|
||||
-0.0135 -0.0301 -0.0582 -0.0964 -0.1353 -0.1572 -0.1433 -0.0864 0
|
||||
-0.0209 -0.0466 -0.0901 -0.1493 -0.2096 -0.2435 -0.2219 -0.1338 0
|
||||
-0.0285 -0.0637 -0.1231 -0.2041 -0.2865 -0.3328 -0.3033 -0.1829 0
|
||||
-0.0344 -0.0769 -0.1485 -0.2461 -0.3456 -0.4014 -0.3658 -0.2206 0
|
||||
-0.0366 -0.0818 -0.1581 -0.2620 -0.3679 -0.4273 -0.3894 -0.2349 0
|
||||
-0.0344 -0.0769 -0.1485 -0.2461 -0.3456 -0.4014 -0.3658 -0.2206 0
|
||||
-0.0285 -0.0637 -0.1231 -0.2041 -0.2865 -0.3328 -0.3033 -0.1829 0
|
||||
-0.0209 -0.0466 -0.0901 -0.1493 -0.2096 -0.2435 -0.2219 -0.1338 0
|
||||
-0.0135 -0.0301 -0.0582 -0.0964 -0.1353 -0.1572 -0.1433 -0.0864 0
|
||||
-0.0077 -0.0172 -0.0331 -0.0549 -0.0771 -0.0896 -0.0816 -0.0492 0
|
||||
-0.0039 -0.0086 -0.0167 -0.0276 -0.0388 -0.0450 -0.0410 -0.0248 0
|
||||
-0.0017 -0.0038 -0.0074 -0.0123 -0.0172 -0.0200 -0.0182 -0.0110 0
|
||||
-0.0007 -0.0015 -0.0029 -0.0048 -0.0067 -0.0078 -0.0071 -0.0043 0
|
||||
|
||||
Columns 10 through 17:
|
||||
|
||||
0.0043 0.0071 0.0078 0.0067 0.0048 0.0029 0.0015 0.0007
|
||||
0.0110 0.0182 0.0200 0.0172 0.0123 0.0074 0.0038 0.0017
|
||||
0.0248 0.0410 0.0450 0.0388 0.0276 0.0167 0.0086 0.0039
|
||||
0.0492 0.0816 0.0896 0.0771 0.0549 0.0331 0.0172 0.0077
|
||||
0.0864 0.1433 0.1572 0.1353 0.0964 0.0582 0.0301 0.0135
|
||||
0.1338 0.2219 0.2435 0.2096 0.1493 0.0901 0.0466 0.0209
|
||||
0.1829 0.3033 0.3328 0.2865 0.2041 0.1231 0.0637 0.0285
|
||||
0.2206 0.3658 0.4014 0.3456 0.2461 0.1485 0.0769 0.0344
|
||||
0.2349 0.3894 0.4273 0.3679 0.2620 0.1581 0.0818 0.0366
|
||||
0.2206 0.3658 0.4014 0.3456 0.2461 0.1485 0.0769 0.0344
|
||||
0.1829 0.3033 0.3328 0.2865 0.2041 0.1231 0.0637 0.0285
|
||||
0.1338 0.2219 0.2435 0.2096 0.1493 0.0901 0.0466 0.0209
|
||||
0.0864 0.1433 0.1572 0.1353 0.0964 0.0582 0.0301 0.0135
|
||||
0.0492 0.0816 0.0896 0.0771 0.0549 0.0331 0.0172 0.0077
|
||||
0.0248 0.0410 0.0450 0.0388 0.0276 0.0167 0.0086 0.0039
|
||||
0.0110 0.0182 0.0200 0.0172 0.0123 0.0074 0.0038 0.0017
|
||||
0.0043 0.0071 0.0078 0.0067 0.0048 0.0029 0.0015 0.0007
|
||||
|
||||
octave:108> figure
|
||||
octave:109> surf(A1, B1, F)
|
||||
octave:110> figure
|
||||
octave:111> mesh(A1, B1, F)
|
||||
octave:112> close all
|
||||
octave:113> help quiver
|
||||
'quiver' is a function from the file /usr/share/octave/7.3.0/m/plot/draw/quiver.m
|
||||
|
||||
-- quiver (U, V)
|
||||
-- quiver (X, Y, U, V)
|
||||
-- quiver (..., S)
|
||||
-- quiver (..., STYLE)
|
||||
-- quiver (..., "filled")
|
||||
-- quiver (HAX, ...)
|
||||
-- H = quiver (...)
|
||||
|
||||
Plot a 2-D vector field with arrows.
|
||||
|
||||
Plot the (U, V) components of a vector field at the grid points
|
||||
defined by (X, Y). If the grid is uniform then X and Y can be
|
||||
specified as vectors and 'meshgrid' is used to create the 2-D grid.
|
||||
|
||||
If X and Y are not given they are assumed to be '(1:M, 1:N)' where
|
||||
'[M, N] = size (U)'.
|
||||
|
||||
The optional input S is a scalar defining a scaling factor to use
|
||||
for the arrows of the field relative to the mesh spacing. A value
|
||||
of 1.0 will result in the longest vector exactly filling one grid
|
||||
square. A value of 0 disables all scaling. The default value is
|
||||
0.9.
|
||||
|
||||
The style to use for the plot can be defined with a line style
|
||||
STYLE of the same format as the 'plot' command. If a marker is
|
||||
specified then the markers are drawn at the origin of the vectors
|
||||
(which are the grid points defined by X and Y). When a marker is
|
||||
specified, the arrowhead is not drawn. If the argument "filled" is
|
||||
given then the markers are filled.
|
||||
|
||||
If the first argument HAX is an axes handle, then plot into this
|
||||
axes, rather than the current axes returned by 'gca'.
|
||||
|
||||
The optional return value H is a graphics handle to a quiver
|
||||
object. A quiver object regroups the components of the quiver plot
|
||||
(body, arrow, and marker), and allows them to be changed together.
|
||||
|
||||
Example:
|
||||
|
||||
[x, y] = meshgrid (1:2:20);
|
||||
h = quiver (x, y, sin (2*pi*x/10), sin (2*pi*y/10));
|
||||
set (h, "maxheadsize", 0.33);
|
||||
|
||||
See also: quiver3, compass, feather, plot.
|
||||
|
||||
Additional help for built-in functions and operators is
|
||||
available in the online version of the manual. Use the command
|
||||
'doc <topic>' to search the manual index.
|
||||
|
||||
Help and information about Octave is also available on the WWW
|
||||
at https://www.octave.org and via the help@octave.org
|
||||
mailing list.
|
||||
octave:114> help quiver3
|
||||
'quiver3' is a function from the file /usr/share/octave/7.3.0/m/plot/draw/quiver3.m
|
||||
|
||||
-- quiver3 (X, Y, Z, U, V, W)
|
||||
-- quiver3 (Z, U, V, W)
|
||||
-- quiver3 (..., S)
|
||||
-- quiver3 (..., STYLE)
|
||||
-- quiver3 (..., "filled")
|
||||
-- quiver3 (HAX, ...)
|
||||
-- H = quiver3 (...)
|
||||
|
||||
Plot a 3-D vector field with arrows.
|
||||
|
||||
Plot the (U, V, W) components of a vector field at the grid points
|
||||
defined by (X, Y, Z). If the grid is uniform then X, Y, and Z can
|
||||
be specified as vectors and 'meshgrid' is used to create the 3-D
|
||||
grid.
|
||||
|
||||
If X and Y are not given they are assumed to be '(1:M, 1:N)' where
|
||||
'[M, N] = size (U)'.
|
||||
|
||||
The optional input S is a scalar defining a scaling factor to use
|
||||
for the arrows of the field relative to the mesh spacing. A value
|
||||
of 1.0 will result in the longest vector exactly filling one grid
|
||||
cube. A value of 0 disables all scaling. The default value is
|
||||
0.9.
|
||||
|
||||
The style to use for the plot can be defined with a line style
|
||||
STYLE of the same format as the 'plot' command. If a marker is
|
||||
specified then the markers are drawn at the origin of the vectors
|
||||
(which are the grid points defined by X, Y, Z). When a marker is
|
||||
specified, the arrowhead is not drawn. If the argument "filled" is
|
||||
given then the markers are filled.
|
||||
|
||||
If the first argument HAX is an axes handle, then plot into this
|
||||
axes, rather than the current axes returned by 'gca'.
|
||||
|
||||
The optional return value H is a graphics handle to a quiver
|
||||
object. A quiver object regroups the components of the quiver plot
|
||||
(body, arrow, and marker), and allows them to be changed together.
|
||||
|
||||
[x, y, z] = peaks (25);
|
||||
surf (x, y, z);
|
||||
hold on;
|
||||
[u, v, w] = surfnorm (x, y, z / 10);
|
||||
h = quiver3 (x, y, z, u, v, w);
|
||||
set (h, "maxheadsize", 0.33);
|
||||
|
||||
See also: quiver, compass, feather, plot.
|
||||
|
||||
Additional help for built-in functions and operators is
|
||||
available in the online version of the manual. Use the command
|
||||
'doc <topic>' to search the manual index.
|
||||
|
||||
Help and information about Octave is also available on the WWW
|
||||
at https://www.octave.org and via the help@octave.org
|
||||
mailing list.
|
||||
octave:115> help feather
|
||||
'feather' is a function from the file /usr/share/octave/7.3.0/m/plot/draw/feather.m
|
||||
|
||||
-- feather (U, V)
|
||||
-- feather (Z)
|
||||
-- feather (..., STYLE)
|
||||
-- feather (HAX, ...)
|
||||
-- H = feather (...)
|
||||
|
||||
Plot the '(U, V)' components of a vector field emanating from
|
||||
equidistant points on the x-axis.
|
||||
|
||||
If a single complex argument Z is given, then 'U = real (Z)' and 'V
|
||||
= imag (Z)'.
|
||||
|
||||
The style to use for the plot can be defined with a line style
|
||||
STYLE of the same format as the 'plot' command.
|
||||
|
||||
If the first argument HAX is an axes handle, then plot into this
|
||||
axes, rather than the current axes returned by 'gca'.
|
||||
|
||||
The optional return value H is a vector of graphics handles to the
|
||||
line objects representing the drawn vectors.
|
||||
|
||||
phi = [0 : 15 : 360] * pi/180;
|
||||
feather (sin (phi), cos (phi));
|
||||
|
||||
See also: plot, quiver, compass.
|
||||
|
||||
Additional help for built-in functions and operators is
|
||||
available in the online version of the manual. Use the command
|
||||
'doc <topic>' to search the manual index.
|
||||
|
||||
Help and information about Octave is also available on the WWW
|
||||
at https://www.octave.org and via the help@octave.org
|
||||
mailing list.
|
||||
octave:116> figure
|
||||
octave:117> imshow([1 0; 0 1])
|
||||
octave:118> imshow(1:255)
|
||||
octave:119> imshow([1 .5; .5 1])
|
||||
octave:120> whos
|
||||
Variables visible from the current scope:
|
||||
|
||||
variables in scope: top scope
|
||||
|
||||
Attr Name Size Bytes Class
|
||||
octave:124> whos
|
||||
octave:125> x = [1 0; 0 1]
|
||||
x =
|
||||
|
||||
1 0
|
||||
0 1
|
||||
|
||||
octave:126> whose
|
||||
error: 'whose' undefined near line 1, column 1
|
||||
octave:127> whos
|
||||
Variables visible from the current scope:
|
||||
|
||||
variables in scope: top scope
|
||||
|
||||
Attr Name Size Bytes Class
|
||||
==== ==== ==== ===== =====
|
||||
x 2x2 32 double
|
||||
|
||||
Total is 4 elements using 32 bytes
|
||||
|
||||
octave:128> imshow(x)
|
||||
octave:129> imshow(int(x))
|
||||
error: 'int' undefined near line 1, column 8
|
||||
octave:130> int
|
||||
int16 int64 integral2 interp2 interpn intmin
|
||||
int2str int8 integral3 interp3 intersect
|
||||
int32 integral interp1 interpft intmax
|
||||
octave:130> imshow(int8(x))
|
||||
error: imshow: invalid data type for image
|
||||
error: called from
|
||||
imshow at line 199 column 9
|
||||
octave:131> close all
|
||||
octave:132> image = reshape(linspace(0, 1, 12), 2, 2, 3)
|
||||
image =
|
||||
|
||||
ans(:,:,1) =
|
||||
|
||||
0 0.1818
|
||||
0.0909 0.2727
|
||||
|
||||
ans(:,:,2) =
|
||||
|
||||
0.3636 0.5455
|
||||
0.4545 0.6364
|
||||
|
||||
ans(:,:,3) =
|
||||
|
||||
0.7273 0.9091
|
||||
0.8182 1.0000
|
||||
|
||||
octave:133> imshow(image)
|
||||
octave:134> image(:, :, 3) = 0
|
||||
image =
|
||||
|
||||
ans(:,:,1) =
|
||||
|
||||
0 0.1818
|
||||
0.0909 0.2727
|
||||
|
||||
ans(:,:,2) =
|
||||
|
||||
0.3636 0.5455
|
||||
0.4545 0.6364
|
||||
|
||||
ans(:,:,3) =
|
||||
|
||||
0 0
|
||||
0 0
|
||||
|
||||
octave:135> imshow(image)
|
||||
octave:136> image(:, :, 2) = 0
|
||||
image =
|
||||
|
||||
ans(:,:,1) =
|
||||
|
||||
0 0.1818
|
||||
0.0909 0.2727
|
||||
|
||||
ans(:,:,2) =
|
||||
|
||||
0 0
|
||||
0 0
|
||||
|
||||
ans(:,:,3) =
|
||||
|
||||
0 0
|
||||
0 0
|
||||
|
||||
octave:137> imshow(image)
|
||||
octave:138> close all
|
||||
octave:139>
|
152
lessons/lesson03/plotting.m
Normal file
152
lessons/lesson03/plotting.m
Normal file
@ -0,0 +1,152 @@
|
||||
%% Lesson 5a: Plotting
|
||||
%
|
||||
% We are going to go through several plotting schemes, and explore how you
|
||||
% can customize plotting. We would go through 2D plotting, surface
|
||||
% plotting, subplot, stem plot and 3D plotting
|
||||
%
|
||||
% In this file the `command syntax` style of functions will be used when
|
||||
% possible, just to get you familiar with the style.
|
||||
clear; clc; close all;
|
||||
|
||||
%% 2D plotting: line graphs
|
||||
% In general, always annotate your plots appropriately! Use a title,
|
||||
% axis labels, legends, etc. as necessary. Set appropriate bounds,
|
||||
% appropriate scaling (e.g., linear vs. logarithmic), and the correct
|
||||
% type of plot. We'll start simple with line plots.
|
||||
x = -10:0.1:10;
|
||||
y = x.^3;
|
||||
y2 = x.^2;
|
||||
|
||||
hold on; % plotting more than 1 plot on 1 figure rather than overwriting
|
||||
|
||||
plot(x, y, 'DisplayName', 'x^3');
|
||||
plot(x, y2, 'DisplayName', 'x^2');
|
||||
|
||||
hold off;
|
||||
|
||||
xlabel 'x axis';
|
||||
ylabel 'y axis';
|
||||
title 'Example 1';
|
||||
xlim([-10 10]);
|
||||
ylim([-10 10]);
|
||||
% axis([-10 10 -10 10]);
|
||||
grid on;
|
||||
legend show; % 'DisplayName does this
|
||||
|
||||
%% Example 2: Plotting sine and cosine
|
||||
t = 0:.1:10;
|
||||
d1 = sin(t);
|
||||
d2 = cos(t);
|
||||
|
||||
figure;
|
||||
|
||||
% plot(t, [d1.' d2.']);
|
||||
% plot(t, d1, t, d2);
|
||||
|
||||
hold on;
|
||||
plot(t, d1);
|
||||
plot(t, d2);
|
||||
hold off;
|
||||
|
||||
title 'Trig Functions';
|
||||
|
||||
% We can use some LaTeX-like symbols like \mu, \beta, \pi, \leq, \infty.
|
||||
% For full LaTeX support use the `Interpreter: latex` option
|
||||
xlabel 'time (\mu)s';
|
||||
|
||||
ylabel voltage;
|
||||
legend sin cos;
|
||||
|
||||
% Save to file; gcf() is "get current figure"
|
||||
exportgraphics(gcf(), "sample_plot.png");
|
||||
|
||||
%% More plotting options
|
||||
% Legends, axis ticks (and labels), LaTeX interpreter
|
||||
figure;
|
||||
|
||||
% Options for changing line pattern and color.
|
||||
% Don't need `hold on`/`hold off` if multiple lines plotted with a single
|
||||
% `plot` function.
|
||||
plot(t, d1, 'b-.', t, d2, 'rp');
|
||||
|
||||
title 'Trig Functions';
|
||||
xlabel 'time ($\mu$s)' Interpreter latex
|
||||
ylabel voltage;
|
||||
legend('sin', 'cos');
|
||||
xticks(0:pi/2:10);
|
||||
xticklabels({'0', '\pi/2', '\pi', '3\pi/2', '2\pi', '5\pi/2', '3\pi'});
|
||||
|
||||
% Many other options availible for plotting. Check the documentation or
|
||||
% search online for options.
|
||||
|
||||
%% Subplots
|
||||
% Subplots exist for stylistic purposes. Let's say you have a signal and
|
||||
% you want to plot the magnitude and phase of the signal itself. It would
|
||||
% make more sense if the magnitude and phase plots exist in the same
|
||||
% figure. There are several examples fo subplot below to explain how it
|
||||
% works. Note that linear indexing of plots is different from normal linear
|
||||
% indexing.
|
||||
|
||||
figure;
|
||||
subplot(2,2,1); % subplot(# of rows, # of columns, index)
|
||||
plot(t,d1);
|
||||
hold on;
|
||||
plot(t, d2);
|
||||
title 'Normal plot';
|
||||
|
||||
subplot(2, 2, 2); % index runs down rows, not columns!
|
||||
plot(t, d1, 'b-.', t, d2, 'rp');
|
||||
title 'Customized plot';
|
||||
|
||||
%% Stem plots
|
||||
% stem plots are particularly useful when you are representing digital
|
||||
% signals, hence it is good (and necessary) to learn them too!
|
||||
% subplot(2,2,[3 4]) % takes up two slots
|
||||
subplot(2, 1, 2);
|
||||
hold on;
|
||||
stem(t, d1);
|
||||
stem(t, d2);
|
||||
hold off;
|
||||
title 'Stem plots';
|
||||
|
||||
sgtitle Subplots;
|
||||
|
||||
%% Tiling -- like subplots but newer
|
||||
figure;
|
||||
tiledlayout(2, 2);
|
||||
|
||||
nexttile;
|
||||
plot(t, d1);
|
||||
|
||||
nexttile;
|
||||
plot(t, d2);
|
||||
|
||||
%% A 3-D parametric function
|
||||
% A helix curve
|
||||
t = linspace(0,10*pi);
|
||||
|
||||
figure;
|
||||
plot3(sin(t), cos(t), t);
|
||||
xlabel sin(t);
|
||||
ylabel cos(t);
|
||||
zlabel t;
|
||||
text(0, 0, 0, 'origin');
|
||||
grid on;
|
||||
title Helix;
|
||||
|
||||
%% Surface plot
|
||||
% A shaded look for 2-D functions
|
||||
%
|
||||
% $f(x) = x\exp -(x^2+y^2)$
|
||||
a1 = -2:0.25:2;
|
||||
b1 = a1;
|
||||
[A1, B1] = meshgrid(a1);
|
||||
F = A1.*exp(-A1.^2-B1.^2);
|
||||
|
||||
figure;
|
||||
surf(A1,B1,F);
|
||||
|
||||
%% Mesh plot
|
||||
% A wireframe look for 2-D functions
|
||||
figure;
|
||||
mesh(A1,B1,F);
|
Reference in New Issue
Block a user