Compare information from table to string
显示 更早的评论
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 个评论
Mark Sherstan
2018-11-19
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!