MATLAB: How to organize the data into 12 rows of different lengths

data organizationdatastoreMATLAB and Simulink Student Suite

The data I'm working with consists of 12 sets of tab delimited numbers. However, each set begins with A1, A2 etc.. The issue I'm facing is that when I import my data, my first line (A1) contains only 2144 numbers, while subsequent lines have many more. Because of the size of the first set, when I create a table or datastore, it always contains 2144 variables, which means the larger data sets spill over into several rows.
Ideally my end result would have 12 rows (A1, A2, A3, A4, B1-4, C1-4), each containing as many columns as necessary to accommodate the largest set.
How can I import/manipulate my data to organize it in this way? I've included my data file.

Best Answer

I would put the data into a cell array, because it is easy to to import the data and split it into a cell array, it makes accessing the data easy, and it does not require data duplication.
>> str = fileread('DATA_w0IntDen.txt'); % read file data.
>> tkn = regexp(str,'([A-Z]\d+)(\s+\d+)+','tokens'); % identify sets of data.
>> tkn = vertcat(tkn{:});
>> fun = @(s)sscanf(s,'%f',[1,Inf]); % function to convert char -> numeric
>> tkn(:,2) = cellfun(fun,tkn(:,2),'uni',0); % convert to numeric.
The first column of tkn contains the 'A1', etc., char vectors, while the second column contains the numeric data. Lets check the first row:
>> tkn{1,1}
ans =
A1
>> tkn{1,2}
ans =
15586 55225 1575 1997 ... lots here ... 2685 2627 3692 2345
If you really want to generate one numeric array from this, then download padcat and use it like this:
mat = padcat(tkn{:,2})