% A script to automate the analysis of bridges of the world

% Input file required: bridges_of_the_world_short
% Finds: bridges built after the year 2001
% Concepts:
%     a) reading a file with string and numeric data
%     b) illustrates the conceptopt a pointer array in Matlab
%     c) exports data to another file

% Read the data. The format of the data read is four columns as follows:

% Name  	Country  	Completed  	 Length (m) 
% Mackinac	United States	1957	8038 
% Xiasha	China	1991	8230 
% Virginia-Dare-Memorial	United States	2002	8369 

fid = fopen('bridges_of_the_world_short');                % open the file (Matlab assigns a file ID)

readHeader = textscan(fid, '%s', 4, 'delimiter', '|');      % read four columns in first row with "|" delimiter
readData = textscan(fid, '%s %s %f %f');                      % read four columns with two strings and two floating point (numbers)
fclose(fid)                                                                 % closes the file that we opened in line 17

% Define new variables before doing any analysis

bridgeName = readData{1};
bridgeCountry = readData{2};
yearOfConstruction = readData{3};
bridgeLength = readData{4};

% Analysis of the data read

% Find all bridges built between year 1963 and 2000
% the variable "newBridges" is a pointer variable
% it contains the indices of the bridges that meet the
% above criteria

% Note: we used "&" used as "and" (conditional statement)

newBridges = find(yearOfConstruction > 1963 & yearOfConstruction <2001);        

% Extract the names of the bridges found and save with a new variable name

newBridgesNames = bridgeName(newBridges);        % saves names in a new array
newBridgesYear = yearOfConstruction(newBridges); % saves the year of construction for 
                                                                              % the bridges found
















