uno.mrooms3.net net/pluginfile Pr am description Consider each direct route (a,
ID: 2292041 • Letter: U
Question
uno.mrooms3.net net/pluginfile Pr am description Consider each direct route (a, b, c, d, e) in the previous example as a number of miles between two cities. For example, City 3 and City 4 are b miles away from each other. Table 1 can be modified to present the distances: Table 2. Distances among four cities City 1 City 3 Ct City 2 City 4 City1 City 2 City 3 City 4 Page 2 of 3 ENEE 1530 Project 2 Write a MATLAB program that reads in a distance table like Table 2 where a, b, c, and d are positive non-zero real numbers representing distances in miles. The program displays the list of cities on screen and prompts a user for a departing city and a destination city. The program then calculates the total number of direct and one-stop routes between the two cities, and displays it on screen. The program finishes with calculating the distance of each of the direct and one-stop routes between the two cities, displays it on screen, and write it on an Excel file as output. A sample display of results after a user chooses City 4 as departure and City 1 as destination are shown below. The green colored texts are entered by a user >> myproj ('connectivity.xlsx') Cities to choose from: 1, 2, 3, 4 Departure city: 4 Destination city: 1 Total number of routes:3 Sto Direct City 2 City 3 Distance e+d b+ a Routes and distances written to connectivity.xlsx. Goodbye!Explanation / Answer
MATLAB CODE:
1. Create your .XLSX file with any number of cities and there between distance
2. Give the path of your .xlsx file in the specified places mentioned in the code
3. Copy the given script in your matlab editor window and play it.
4. Code is self explanatory. Once go through the code.
%% code starts here
close all
clear all
clc
table = readtable('E:CHEGG able1.xlsx') //give the path of your table with any number of city and there distances
table = xlsread('E:CHEGG able1.xlsx'); //give the path of your table with any number of city and there distances
L=length(table);
disp(['Cities to chose from: 1 to ',num2str(L)])
prompt='Departure City:';
depcity=input(prompt);
while (depcity>L)
disp('NOT a VALID city. Please enter VALID city')
prompt='Departure City:';
depcity=input(prompt);
end
prompt='Destination City:';
descity=input(prompt);
while (descity>L)
disp('NOT a VALID city. Please enter VALID city')
prompt='Destination City:';
descity=input(prompt);
end
dep=table(depcity,:);
des=table(descity,:);
routes=0;
for i=1:L
if dep(1,i)~=0
routes=routes+1;
end
end
disp(['Total number of routes:',num2str(routes)])
direct=dep(descity);
disp('STOP DISTANCE')
disp(['Direct ',num2str(direct),' Miles'])
j=0;
if routes>1
for i=1:L
if i~=descity && i~=depcity
j=j+1;
route(j,1)=dep(i) + des(i);
disp(['City',num2str(i),' ',num2str(dep(i)),'+',num2str(des(i)),'=',num2str(route(j,1)),' Miles'])
end
end
end
%% Code Ends
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.