% A file with the .m suffix can contain a script of commands to be run
% in sequence. To execute this script, type 'example2' at the octave prompt.
% Note that the .m file must exist either in the current working directory
% or in octave's search path. To learn what is in Octave's search path,
% type the 'path' command at the octave prompt.

T = dlmread('myfile.txt','\t');

x = T(:,2);  % The : means all valid values of the (row) index.
y = T(:,3);

figure(1)  % This controls which window the figure (plot) will appear in...
hold off  % Just in case there's an existing figure on the screen.
plot(x,y);
hold on

% Now overplot a very nice circle with fine resolution.
theta = 0:0.01:2*pi; % You'll be sorry if you forget the semicolon...
xbig = cos(theta);
ybig = sin(theta);
plot(xbig,ybig)
plot(0.75*xbig, 1.5*ybig) % an ellipse. 
   % Note how the figure resized itself to accommodate a wider range of values.
   
% A nicer way to make a figure.
figure(2)  % You can have lots of numbered figures on the screen at once.
hold off
plot(x, y, 'bo', 'markersize',15, xbig, ybig, 'g', 0.75*xbig, 1.5*ybig, 'k');
legend('points from myfile.txt', 'smooth circle', 'ellipse');
title('Plot of circles (from example2.m)');
xlabel('x (furlongs)');
ylabel('y (furlongs)');
axis('equal');  % Make circles look like circles, and ellipses like ellipses!
   % This command specifies that 1 unit in x is the same size as 1 unit in y.
print('myplot.pdf', '-dpdfwrite');  % High quality PDF output!

% One more plot...
tantheta = divide(ybig, xbig);  % divide is a user-definded function. Look at divide.m.
figure(3)
hold off
plot(theta, tantheta, 'b', 'linewidth', 2)
axis([0,2*pi,-5,10])
hold on
% Overplot some helpful fiducial lines:
plot([pi/2, pi/2], [-5,10], 'k', [3*pi/2, 3*pi/2], [-5,10], 'k:', [0,2*pi], [0,0], 'k:')
title("Plot of sine over cosine")
xlabel('\theta')
ylabel('tan (\theta)')
print('tantheta.pdf', '-dpdfwrite');
