Problems in reading large matrix with large empty cells
1 view (last 30 days)
I am facing problem in reading a large matrix with header file containing values and missing data/empty cells in each column. A few days ago, I have enquired for similar matrix, which could be read with fixedWidthImportOptions, however with simpler matrix: https://de.mathworks.com/matlabcentral/answers/451154-problems-with-empty-cell-in-a-large-matrix?s_tid=srchtitle
But for this case, matrix dimension are pretty complex with some more values. Could any one pls. suggest how to read in this case, especially for fixing 'VariableWidths'. I am attaching the sample matrix here for your reference.
per isakson on 7 May 2021
Edited: per isakson on 7 May 2021
This script reads your sample file
opts = fixedWidthImportOptions('NumVariables',36,'DataLines',4,...
T = readtable('Test_data.txt', opts );
Determine the column widths based on the header line (second line). The widths of the columns " Cl A" differ between header and data. The first and last column must be added determined visually.
hdr = 'INDEX YEAR MN HR DT ...SLP ..MSLP ..DBT ..WBT ..DPT .RH ..VP DD FFF AW VV Cl A Cm A Ch A Dl Dm Dh TC h c a Ht ..R/F .EVP DW P H .WAT';
pos = strfind( hdr, ' ' );
dpos = diff(pos)
A ruler like this is useful, especially if the header line is not as good as this one.
chr = '42182 1970 01 03 20 0987.1 1012.5 15.6 15.0 14.6 093 16.6 14 004 12 96 9 5 2 2 0 0 9 9 0 7 5 9 1 30 010.5 01.5';
db_ruler( chr )