Problems in reading large matrix with large empty cells
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Poulomi Ganguli
le 6 Mai 2021
Modifié(e) : per isakson
le 7 Mai 2021
Hello:
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.
3 commentaires
Réponse acceptée
per isakson
le 7 Mai 2021
Modifié(e) : per isakson
le 7 Mai 2021
This script reads your sample file
%%
opts = fixedWidthImportOptions('NumVariables',36,'DataLines',4,...
'VariableNames',{'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'},...
'VariableWidths',[5,5,3,3,3,7,7,6,6,6,4,5,3,4,3,3,2,3,2,3,2,3,2,3,3,3,3,2,2,3,6,5,3,2,2,5],...
'VariableTypes',repmat("double",1,36));
T = readtable('Test_data.txt', opts );
T
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 )
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!