Question: Hello, I am getting this error when I run my lab 3 code in MATLAB (after I enter the second city) Incorrect number or

Hello,

I am getting this error when I run my lab 3 code in MATLAB (after I enter the second city)

"Incorrect number or types of inputs or outputs for function 'shortestpath'.

Error in lab3 (line 30) shortest_distance = shortestpath(city1,city2,distance_matrix); "

Lab3

% Define the distance matrix

distance_matrix = [0, 254, 70, 149, 155;

254, 0, 144, 39, 39;

70, 144, 0, 91, 112;

149, 39, 91, 0, 150;

155, 39, 112, 150, 0];

% Ask the user to input the two cities

city1 = input("Enter the first city: ", 's');

city2 = input("Enter the second city: ", 's');

% Define a function that calculates the shortest distance between two cities

shortest_distance = shortestpath(city1, city2, distance_matrix);

% Define the cities array

cities = ["Orangeville", "Owen Sound", "Southern Ontario", "Bradford", "COM"];

% Find the index of the two cities

city1_index = find(cities == city1);

city2_index = find(cities == city2);

% Call the function to calculate the shortest distance

shortest_distance()

% Calculate the shortest distance

shortest_distance = distance_matrix(city1_index, city2_index)

% Display the result

fprintf("The shortest distance between %s and %s is %d km ", city1, city2, shortest_distance);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!