Hello, I have two questions: How do I determine if there is a direct route between x and y in this code? How do I determine the one-stop routes in this code? Thank you

1 Ansicht (letzte 30 Tage)
Hello, I'm a novice at MatLab and I need some assitance with a few lines of code. Thank you for your help.
Notice: To clarify, I'm not asking you to work out the entire project or anything like that. I will post the prompt the teacher has given us and the example just incase y'all need that information. I will also be posting my code. Sorry if this comes off as rude, just don't want to send the wrong idea.
Problems I need assitance with:
How do I determine if there is a direct route between x and y?
How do I determine the one-stop routes?
These will be all the way at the bottom of the code, the comments label them
Prompt:
Table 2 Example from Prompt:
My code:
myproj('City.xlsx')
function myproj(fname)
miles = xlsread(fname);
A = (miles > 0);
B = A.^2;
fprintf('Cities to choose from: ');
disp(1:length(A));
x = input('Departure city: ');
y = input('Destination city: ');
fprintf('\n');
if x == y
disp('You entered the same Departure city and Destination city!\n')
else
% Display number of routes
total_routes = A(x,y) + B(x,y);
str1 = sprintf('Total numbers of routes: %d', total_routes);
disp(str1);
% Start a table on screen
xlswrite('City.xlsx',x);
xlswrite('City.xlsx',y);
disp('Stop Distance');
% Set up column headings in Excel
str2 = sprintf('Routes between City %d and City %d', x, y);
xlswrite(fname, {str2}, 2, 'A1');
xlswrite(fname, {str1}, 2, 'A2');
xlswrite(fname, {'Stop'}, 2, 'A3');
xlswrite(fname, {'Distance'}, 2, 'B3');
% Prepare vectors for writing to Excel
xlswrite(fname, A, 'A1');
routes(1:total_routes, 1) = {' '}; % Route name (Direct or City name)
distances(1:total_routes, 1) = 0; % Mile of each route
num_route = 0; % Keep track of row number in matrix “routes” and “distances”
% Determine if there is a direct route between Cities x and y
if(A(2,i) == 1)
dirroute = miles(2,i);
end
% Display on screen and also add the route to “routes” and “distances” for Excel
disp(['City',num2str(1i),' ',num2str(dep(i)),'+',num2str(des(i)),'=',num2str(routes(j,1)),' Miles'])
% Determine one-stop routes between x and y
% Display on screen and also add the route to “routes” and “distances” for Excel
% Writing results to Excel
end
end
  4 Kommentare
John D'Errico
John D'Errico am 4 Mai 2022
There should be a button on the top right that says edit, with a little icon that looks like a pencil.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by