MATLAB: Need to output the data which is currently in a for loop to a table!

dataloopsMATLABtable

I have a set of data which I had to read into matlab using a for loop, the code which works nicely is shown below:
directory = 'C:\Users\....';
listing = dir(directory);
for i = 1:length(listing)
if strcmp(listing(i).name, '.') || strcmp(listing(i).name, '..')
continue
end;
file = listing(i).name;
currfile = fopen(strcat(directory,listing(i).name));
tline = fgets(currfile);
fclose(currfile);
end;
However, when you look at what "tline" outputs, it produces this as shown below:
tline =
Bolton,26.000,88.571,70.000,77.943,63.091,36.700,47.400,48.200
tline =
Thames Valley,33.000,94.286,68.667,78.657,61.455,30.500,51.600,37.300
tline =
London S Bank,28.000,81.429,84.000,76.514,64.909,28.000,51.600,43.700
This is fine, it's exactly what I want but I can't figure out how to then transform what's shown above into a nice table with 9 columns and headings. I am able to create a table taking out that data using this code shown below:
T = table({'London S Bank'},[28.000],[81.429],[84.000],[76.514],[64.909],[28.000],[51.600],[43.700], 'VariableNames', {'UN','SS','RQ','SR','SF','ES','C','GH','GP'})
But I have 113 lines of data which needs to all be in the same table. Any ideas how I can do this straight from my loop without typing out all the data?
Thank you!

Best Answer

Olivia, all you have are strings, and presumably you want one column of strings and eight columns of numbers. TastyPastry's suggestion will work, but likely you would need use str2double somewhere in the process to convert strings like '26.000' to actual numbers.
Another suggestion would be to use textscan to turns each strings into one string and eight numbers, something along the lines of:
tline = cell(113,1);
for i = ...
...
tline{i} = fgets(currfile);
end
C = textscan(strjoin(tline),'%s%f%f%f%f%f%f%f%f','delimiter',',');
T = table(C{:},'VariableNames',{'Location' 'X' 'Y' ...})
This is a somewhat advanced maneuver, but you might find it useful.