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
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started