You are correct that == doesn't work the way you have written it. You have to keep in mind that a table is a container, and so routes(i,3) is a 1x1 table while Departure is (I guess?) a 1x3 char row. Those obviously are not equal. You'd need to compare routes{i,3} to Departure, but you'd also have to use strcmp, not ==.
Allow me to suggest a few things.
1) you may want to convert your tables to timetables, since you have timestamped data.
2) I'm gonna suggest that you convert those arrival/departure data to categorical variables in your table. Among other things, that would allow you to use ==, making your code easier to read.
3) Put meaningful variable names in your table if they are not there already. This lets you say "Departure" instead of "3".
4) Most importantly, get rid of that loop.
Putting all that together, you have
j = (routes.Departure == Departure) && (routes.Arrival == Arrival);
rv = routes(j)
No loop.
Actually, your original code is kind of funny, and seems to assume only one row in your data that match the specified arrival/departure. The above will return all matches, if there are more than one.
Best Answer