MATLAB: Splitting Cells Contents into A Uniform Dimension

cell splittingcellsdata importMATLAB

Hi,
I've been having some issues getting uniform dimensions when I'm splitting my cells.
The code I'm using to split my cell manages to separate my data quite well. The problem is that the data I need to import isn't really consistent with its contents, so some rows end up having blank values and aren't factored into the columnization. i.e. some dimensions in my cell end up being 4×1 or 8×1.
Code Attached Here:
% READ FILE
PROPERTY = textscan(fopen('PROPERTY.txt'),'%s','Delimiter','\n');
% CLOSE FILE
fclose(fopen('PROPERTY.txt'));
% DATA EXTRACTION
PROPERTY = PROPERTY{1,1};
% CELL COLUMNIZATION
PROPERTY = cellfun(@(cIn)strsplit(cIn,' ')',PROPERTY,'UniformOutput',false);
PROPERTY = [PROPERTY {:}]';
This leads to the following output (Attachment 1), as you can see the dimension of the columnized cells end up not being consistent. I'd like to know to create a uniform output in my cell that is 9×1. Replacing any blank data with a 0 for its associated column.
I have also attached the file that I need to extract my data from as well (PROPERTY.txt).
Thanks in advance
EDIT: I should also add, I'm only really concerned about the data in the rows that display atomic data.

Best Answer

Use a FixedWidthImportOptions object to specify the format of your file and import as a table:
opts = matlab.io.text.FixedWidthImportOptions;
opts.DataLines = [2 Inf];
opts.VariableNames = {'NUCLIDE', 'XHL', 'AHL', 'SIGCTH', 'COEFF', 'RIC', 'SIGFTH', 'COEFF', 'RIF'};
opts.VariableWidths = [10 9 1 10 10 10 10 10 10];
opts = setvartype(opts, opts.VariableNames, {'char', 'double', 'char', 'double', 'double', 'double', 'double', 'double', 'double'});
properties = readtable('PROPERTY.txt', opts')