how to reshape the data ?
Show older comments
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.
Accepted Answer
More Answers (1)
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 Comments
pruth
on 16 May 2018
since i am not used to Matlab, i am not able to understand the code u gave.
Based on your posting history, you have been using Matlab for at least 3 years! You ought to be pretty used to it by now.
what is MAT2TILES? how to use after downloading? i am using matlab 2015a. can you find some time to explain this code to me?
For general information about mat2tiles,
>> help mat2tiles
should sort you out. I think it would also be a good idea to run one line of the code at a time and observe the results of each step.
I will mention that the only purpose of the first three lines is to insert dashes in between your date/time fields, i.e., so that we get things like the following, which MATLAB can read more easily.
'18-04-17-00-00-05'
'18-04-17-00-00-15'
'18-04-17-00-00-25'
'18-04-17-00-00-35'
'18-04-17-00-00-45'
'18-04-17-00-00-55'
If you already had the information in this form then we could have simply done
Times=char(data(1:3:end));
Times=Times(:,5:21);
Times=datetime(Times,'InputFormat','yy-MM-dd-HH-mm-ss');
pruth
on 16 May 2018
Ameer Hamza
on 16 May 2018
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.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!