Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

function Name = GetStationName(id) filename = 'divvy-names.csv'; if exist(filename, 'file') ~= 2 %% doesn't exist: fprintf('**Error in GetStationName: cannot find divvy-names.csv file '); Name =

image text in transcribedimage text in transcribedimage text in transcribed

function Name = GetStationName(id)

filename = 'divvy-names.csv';

if exist(filename, 'file') ~= 2 %% doesn't exist:

fprintf('**Error in GetStationName: cannot find "divvy-names.csv" file ');

Name = '?';

return;

end

%% load file of station names, and search for matching id:

%% MATLAB:

%% names = dataset('File', filename, 'Delimiter', ',');

%% LI = (names.ID == id);

%% this works in MATLAB or Octave:

[IDs, Names] = textread('divvy-names.csv', '%d %s', 'delimiter', ',');

LI = (IDs == id);

if sum(LI) == 0 %% not found:

Name = 'Unknown station name';

elseif sum(LI) == 1 %% found match:

I = find(IDs == id); %% what index was match?

Name = Names{I}; %% use { } to extract string @ that index:

else %% found multiple matches, should never happen:

Name = 'Multiple station names found, something is wrong...';

end

end

function Distance = DistBetween2Points(lat1, long1, lat2, long2)

%%

%% Reference: http://www8.nau.edu/cvm/latlon_formula.html

%%

earth_rad = 3963.1; %% statue miles:

lat1_rad = lat1 .* pi ./ 180.0;

long1_rad = long1 .* pi ./ 180.0;

lat2_rad = lat2 .* pi ./ 180.0;

long2_rad = long2 .* pi ./ 180.0;

%% distance between points in statue miles:

Distance = earth_rad .* acos(...

(cos(lat1_rad).*cos(long1_rad).*cos(lat2_rad).*cos(long2_rad)) ...

+ ...

(cos(lat1_rad).*sin(long1_rad).*cos(lat2_rad).*sin(long2_rad)) ...

+ ...

(sin(lat1_rad).*sin(lat2_rad)) ...

);

end

in Matlab, can you help me modify the given function based on given instructions.

Analysis #5: Stations Near Me Analysis #5 performs an operation we are all familiar with: searching for something near us. In this case we'll search for Divvy stations "nearby". The user will input their coordinates1 as (latitude, longitude), along with a distance D (in miles) defining what they mean by "nearby". Your program will then input station data from the file "divvy-stations.csv", and output all stations D miles away. Example Analysis to perform (1-5, 0 to exit)>5 Enter your latitude> 41.86 Enter your longitude -87.62 Within how many miles? 0.5 Station 338: 0.168045 miles, "Calumet Ave & 18th St" Station 273: 0.278975 miles, "Michigan Ave& 18th St" Station 72: 0.300635 miles, "Wabash Ave & 16th St" Station 168: 0.340126 miles, "Michigan Ave&14th St" Station 97: 0.383504 miles, "Field Museum" Station 370: 0.404626 miles, "Calumet Ave&21st St" Station 4: 0.429038 miles, "Burnham Harbor" Station 178: 0.454386 miles, "State St & 19th St" stations: 8 Notice the output is given in ascending order by distance away from the given coordinates; the station name is also output, e.g. "Calumet Ave & 18th St". Use fprintf to produce this output: fprintf ( ' station %d: %f miles, "is" " , . . . ) ; Note that fprintf doesn't always work well with vectors, so you'll need to loop and call fprintf repeatedly for each station you want to output. How can you tell if a station S is within D miles away? A function DistBetween2Points(lat1, long1, lat2 long2) is being provided on the course web page in the file "DistBetween2Points.m". This function returns the distance, in miles, between (lat1, long1) and (lat2, long2), based on the equation defined here. Data about the stations is defined in "divvy-stations.csv", also available on the course web page. You'll need to load this file as part of your station search: 456,41.991178, -87.683593,15 101,41.78101637,-87.57611976,23 109,41.874675, -87.650019,19 The first column is the station ID, columns 2 and 3 are the latitude and longitude of this station, and column 4 Analysis #5: Stations Near Me Analysis #5 performs an operation we are all familiar with: searching for something near us. In this case we'll search for Divvy stations "nearby". The user will input their coordinates1 as (latitude, longitude), along with a distance D (in miles) defining what they mean by "nearby". Your program will then input station data from the file "divvy-stations.csv", and output all stations D miles away. Example Analysis to perform (1-5, 0 to exit)>5 Enter your latitude> 41.86 Enter your longitude -87.62 Within how many miles? 0.5 Station 338: 0.168045 miles, "Calumet Ave & 18th St" Station 273: 0.278975 miles, "Michigan Ave& 18th St" Station 72: 0.300635 miles, "Wabash Ave & 16th St" Station 168: 0.340126 miles, "Michigan Ave&14th St" Station 97: 0.383504 miles, "Field Museum" Station 370: 0.404626 miles, "Calumet Ave&21st St" Station 4: 0.429038 miles, "Burnham Harbor" Station 178: 0.454386 miles, "State St & 19th St" stations: 8 Notice the output is given in ascending order by distance away from the given coordinates; the station name is also output, e.g. "Calumet Ave & 18th St". Use fprintf to produce this output: fprintf ( ' station %d: %f miles, "is" " , . . . ) ; Note that fprintf doesn't always work well with vectors, so you'll need to loop and call fprintf repeatedly for each station you want to output. How can you tell if a station S is within D miles away? A function DistBetween2Points(lat1, long1, lat2 long2) is being provided on the course web page in the file "DistBetween2Points.m". This function returns the distance, in miles, between (lat1, long1) and (lat2, long2), based on the equation defined here. Data about the stations is defined in "divvy-stations.csv", also available on the course web page. You'll need to load this file as part of your station search: 456,41.991178, -87.683593,15 101,41.78101637,-87.57611976,23 109,41.874675, -87.650019,19 The first column is the station ID, columns 2 and 3 are the latitude and longitude of this station, and column 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago