Compare information from table to string
Show older comments
I currently work on a project where I need to compare the input information to the information in the table and then output the row which is matching the input information. The input information is departure and arrival airport, which is represented with 3 capital letters (i.e. 'DEN', 'JFK). The flight data is stored in .txt file, which is then converted to the table in matlab. When I try to run the for loop, MATLAB outputs an error, saying that '==' cannot be used with the table. Can you please help me to solve this issue? I will attach the code and the .txt file below.
function rv = finalproject(Departure, Arrival)
routes = readtable('routes.txt'); % import routes data
planes = readtable('planes.txt'); % import planes data
airlines = readtable('airlines.txt'); % import airlines data
if length(Departure) ~= 3 % check if airport name is correct
error('Check the departure airport')
end
if length(Arrival) ~= 3 % check if airport name is correct
error('Check the arrival airport')
end
for i = 1:67663 % stop when gone through all possible
if routes(i, 3) == Departure && routes(i, 5) == Arrival % find the matching row
rv = routes(i, :); % return the matched row
end
end
end
1 Comment
Mark Sherstan
on 19 Nov 2018
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!