Loading weird data and without extension
2 ビュー (過去 30 日間)
古いコメントを表示
Hello
I'm trying to load that data I got, I'm attaching a few files as an example, it generally goes from 1882 to 2005. Files to up to and including 2002 have no extension, 2002-2005 are dat files. I've tried loading them but with very mixed results, and the older the data goes the more data is missing. I've been using data=importdata but it reads it as three columns (I believe that might be because the headers go Day Month Year).
I would like to import the data and then store it in some structure (I generally would like to extract them column by column, for example a column 13 for each year and each day and store it in a way that makes sense, but at this point I can't even import it).
That's info I got about it:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1563759/image.png)
And I'm interested in data from rows 7 to 13 and columns 13 to 19.
Can anyone think of some way of doing that? I'd greatly appreciate any help.
Thank you
採用された回答
Cris LaPierre
2023 年 12 月 8 日
編集済み: Cris LaPierre
2023 年 12 月 8 日
It does help. So each variable has a width of 6
There are 36 columns of data, 16 rows for each day.
Something like this would work.
unzip('data.zip')
filename = "NH_MSLP_daily_1882";
c = linspace(-180,170,36)
c = [c(c<0)+"W" c(c>0)+"E"];
r = linspace(90,15,16) + "N";
% Extract the date (assumes daily data)
yr = str2double(extract(filename,digitsPattern));
d = datetime(yr,1,1):days(1):datetime(yr,12,31);
D = repmat(d,length(r),1);
degree = repmat(r(:),length(d),1);
% Set import options
opts = fixedWidthImportOptions('NumVariables',length(c));
opts.VariableWidths = ones(1,length(c))*6;
opts.Whitespace = "-";
opts.MissingRule = "omitrow";
opts.VariableTypes = repmat({'double'},1,length(c));
opts.VariableNames = string(c);
opts.VariableNamingRule = "preserve";
% Read the data to a timetable. Times are added to the first column
T = readtimetable(filename,opts,'RowTimes',D(:));
T = addvars(T,degree,'Before',1)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!