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