As per my understanding it is required to create a matrix/table from the data present in the text file.
For the demo purpose I have taken the sample text file which has different number of columns in each row and there are multiple empty cells in each row.
Considering the sample text file with the data as shown below.
Below is the code I have used to import the text file to a matrix.
opts = detectImportOptions('same.txt', 'EmptyLineRule','skip','ExtraColumnsRule','ignore');
opts.MissingRule = 'fill';
opts = setvaropts(opts,'FillValue',0);
myTable = readtable('same.txt',opts);
Below image shows the output matrix of the data present in the text file.
“table2array()” function is used to convert the created table to matrix format.
As required, all the empty cells adn extra column cells are filled with 0.