10. Lines, Shapes, and Images
10.1 Generating lines
10.2 Forming and filling shapes
10.3 Loading images
10.4 Clicking in figure windows to add graphics, add text, or record responses
10.5 Saving and reloading figures
10.6 Practicing lines, shapes, and images
Code 10.1.1
clear all
close all
figure(1)
x = [0 1];
y = [0 1];
our_first_line = plot(x, y);
box on
Output 10.1.1

Code 10.1.2
get(our_first_line)
Output 10.1.2
Color = [0 0 1]
EraseMode = normal
LineStyle = -
LineWidth = [0.5]
Marker = none
MarkerSize = [6]
MarkerEdgeColor = auto
MarkerFaceColor = none
XData = [0 1]
YData = [0 1]
ZData = []
BeingDeleted = off
ButtonDownFcn =
Children = []
Clipping = on
CreateFcn =
DeleteFcn =
BusyAction = queue
HandleVisibility = on
HitTest = on
Interruptible = on
Parent = [151.008]
Selected = off
SelectionHighlight = on
Tag =
Type = line
UIContextMenu = []
UserData = []
Visible = on
Code 10.1.3
figure(2)
delta_y = .5;
our_second_line = plot([min(x) max(x)], …
[min(y)+ delta_y max(y) + delta_y],'color',[1 0 0]);
box on
Output 10.1.3

Code 10.1.4
figure(3)
delta_y = 1;
our_third_line = plot([min(x) max(x)], [min(y)+ 2*delta_y max(y) + 2*delta_y]);
set(our_third_line,'color',[.9 .5 .1], ...
'linestyle','--', ...
'linewidth',8);
box on
Output 10.1.4

Code 10.1.5
set(our_third_line)
Code 10.1.6
set(gca,'XGrid')
set(gcf,'PaperOrientation')
Output 10.1.6
[ on | {off} ]
[ {portrait} | landscape | rotated ]
Code 10.2.1
function my_polygon_1(n,r,c)
x = linspace(0,2*pi,n+1)
x = r*cos(x
y = linspace(0,2*pi,n+1)
y = r*sin(y);
fill(x,y,c)
Code 10.2.2
figure(4)
my_polygon_1(4,1,[.5 .5 .5])
axis square
Output 10.2.2

Code 10.2.3
function my_polygon_2(n,r,c,turn)
x = linspace(0,2*pi,n+1)
x = x + (turn + 1/(2*n))*(2*pi);
x = r*cos(x);
y = linspace(0,2*pi,n+1)
y = y + (turn + 1/(2*n))*(2*pi);
y = r*sin(y);
fill(x,y,c)
Code 10.2.4
figure(5)
hold on
for turn = linspace(-.2,0,5)
my_polygon_2(4,1,[.5 .5 .5],turn)
axis off
end
Output 10.2.4

Code 10.2.5
figure(6)
crazy_x = rand(1,5);
crazy_y = rand(1,5);
f = fill(crazy_x,crazy_y,'g')
set(f,'LineWidth', 5.0);
Output 10.2.5

Code 10.3.1
figure(8)
a = imread('SR_Compat.jpg');
image(a)
axis off
Output 10.3.1

Code 10.3.2
figure(9)
b = imread('lab_photo.jpg');
image(b)
axis off
Output 10.3.2

Code 10.4.1
clear x y
hold on
[x y] = ginput(2);
x = [x(1) x(2) x(2) x(1)];
y = [y(1) y(1) y(2) y(2)];
fill(x,y,'w');
Output 10.4.1

Code 10.4.2
clear x y
[x y] = ginput(1);
text(x,y,'Take the plunge!','rotation',90,'fontsize',24);
Output 10.4.2

Code 10.5.1
saveas(gcf, 'SavedFig9','jpg')
Code 10.5.2
c = imread('SavedFig9.jpg');
image(c)