I'm trying to write a code that searches a list and matches a term. In this case 'bus' what I am then trying to do is to get the values for distance and time for that method and add them to separate lists. Attached is my code
distanceb = [];
timeb = [];
for i =1:n
if strcmp(method(i),'bus') == 1
distanceb = (x(i))
timeb = time(i)
end
end
I can get the values for the x and time but the code seems to overwrite everytime it adds to the list and I get only one answer for distanceb and timeb. Is there a way to add the values to the list without overwriting the previous value?