how to reshape the data ?

1 回表示 (過去 30 日間)
pruth
pruth 2018 年 5 月 16 日
コメント済み: Ameer Hamza 2018 年 5 月 16 日
hi, I have created a mat file(attached). the first row contains headers which I don't need except a date
MRR 180417000005 UTC+0530 AVE 10 STP 200 ASL 450 SMP 125e3 SVS 6.0.0.8 DVS 6.10 DSN 0510076780 CC 2898660 MDQ 100 TYP PRO
here 180417000005 is the YYMMDDHHMMSS. the second row has height-H data and the third row has corresponding rain rate- RR to the height.after that next time scan and continue...
'H 200 400 600 800 .... 5000 5200 5400 5600 5800 6000 6200'
'RR 0.00 0.00 0.00 0.00 ...... 0.00 0.00 0.00 0.00 0.00 0.00 0.00'
I want to create another mat file, which will have the first column of date and time(in Matlab format), the second column will have rain rate at height 200, the third column will have rain rate at height 400. and so on.
  2 件のコメント
Matt J
Matt J 2018 年 5 月 16 日
I don't know if it was intentional, but you have missing data in some of your RR rows. For example,
>> data{20118}
ans =
'RR 6.37 21.18 94.44
pruth
pruth 2018 年 5 月 16 日
hi thank you for the reply. if the data is missing we can put NaN.

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 16 日
The following will return the data in numeric form and store it in a table. Most rows of your table contain 31 column, whereas some rows contain less than 31, in that case, I have padded those rows with NaN at the end
t = char(data(1:3:end));
t = datetime(t(:, 5:16), 'InputFormat', 'yyMMddHHmmss');
rf = cellfun(@(x) str2num(x(3:end)), data(3:3:end), 'UniformOutput', 0);
rf = cellfun(@(x) [x nan(1, 31-numel(x))], rf, 'UniformOutput', 0);
rf = num2cell(cell2mat(rf), 1);
final = [table(t) table(rf{:})];
  2 件のコメント
pruth
pruth 2018 年 5 月 16 日
thank you. it works !!!
just for curiosity !!! can we convert this table in mat file??
Ameer Hamza
Ameer Hamza 2018 年 5 月 16 日
Yes, it is also a MATLAB variable. Just save it in similar way
save('tableFile.mat', 'final')

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2018 年 5 月 16 日
編集済み: Matt J 2018 年 5 月 16 日
This uses MAT2TILES (Download here).
Times=char(data(1:3:end));
Times=string( mat2tiles( Times(:,5:16),[1,2]) );
Times=cell2mat([compose('%s-', Times(:,1:5) ), Times(:,6) ]);
Times=datetime(Times,'InputFormat','yy-MM-dd-HH-mm-ss');
Rainfall=char( data(3:3:end) );
Rainfall=(Rainfall(:,3:end));
result=[char(Times), Rainfall];
  7 件のコメント
Matt J
Matt J 2018 年 5 月 16 日
編集済み: Matt J 2018 年 5 月 16 日
You have to put the mfile somewhere MATLAB can see it - in your current folder where you are running code or somewhere in your matlab path.
Ameer Hamza
Ameer Hamza 2018 年 5 月 16 日
Just the lines
Time = char(data(1:3:end));
Time = datetime(Time(:, 5:16), 'InputFormat', 'yyMMddHHmmss');
work fine in R2018a. I am not sure about the previous version.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by