%
% A11B.m
%
% Read in a data file containing the name, semi-major axis and period of 
% planets in our solar system (as of 2014).
%
% Programming Concepts:  textread command, for loop
%
% INPUT:    User is prompted to enter a number between 1 and 10
% OUTPUT:   The computer tells the user if he/she is a lucky winner
%
% DEPENDENT FILES:  planetsB.txt
%
% Matlab-Monkey.com
% 12/30/2014

% tidy-up your workspace
clc         % clear command window
clear       % clear all variables
close all   % close all graphics windows


% load in data from the file planetsB.txt
% this command will create arrays to store the names of the planets, the
% semi-major axes, and the periods. 
% the final argument represents the number of header lines to skip over. In
% our case, we have one header line, so we pass a 1
[planet, a, P] = textread('planetsB.txt', '%s %f %f', 'headerlines', 1);


% First print a header labeling the columns
fprintf('Planet        semi-major axis (AU)    period (years)\n')

% now print the data. The planet names are stored as cells rather than
% strings, so we need convert each planet name to a string using the char()
% command. Note also that we use %-10s to format the planet names. The '-'
% sign will left justify the names (the default is right-justified).
for i=1:length(a)
     fprintf('%-10s           %6.2f               %6.2f\n',char(planet(i)),a(i),P(i));
end
