How to arrange data -year to seasonal
2 views (last 30 days)
Show older comments
i have 30 yrs data and data period 1970-2001.now i want to do arrange the data of seasonal(November-April) like 1970-71,1971-72,1972-73 up to 2000-01. first i want arrange data like this,then i want to do some statistical analysis on this.
like this 1970 jan feb mar apr ..............dec; 1971 jan feb mar apr ..............dec.
i want this 1970-71 nov dec jan feb mar apr I attached Input format and Output format files here
Thank you
0 Comments
Accepted Answer
Guillaume
on 24 Dec 2014
It looks like all you want to do is rearrange columns and change the row names. So the simplest thing is to load your text file into a table with readtable, copy the table into a new table with the columns you want in to order you want, change the properties of the table and write it back to file with writetable.
As is, your input file cannot be read by matlab because of the missing end of line on the last line, so first open your _'input.txt' into a text editor, and put a carriage return on the last line, then:
oldtable = readtable('input.txt', 'Delimiter', 'tab', 'ReadRowNames', true); %read text file
endyear = oldtable(1:end-1, end-1:end); %Nov and Dec of 1970 to 2000
startnextyear = oldtable(2:end, 1:4); %Jan-Apr of 1971 to 2001
%in order to concatenate tables they must have the same rownames, so rename rows of both tables
newrownames = cellfun(@(y1, y2) strcat(y1, '-', y2(3:end)), oldtable.Properties.RowNames(1:end-1), oldtable.Properties.RowNames(2:end), 'UniformOutput', false); %generate new row names however you want
endyear.Properties.RowNames = newrownames;
startnextyear.Properties.RowNames = newrownames;
%now you can concatenate them:
newtable = [endyear startnextyear];
writetable(newtable, 'output.txt', 'Delimiter', 'tab', 'WriteRowNames', true);
More Answers (0)
See Also
Categories
Find more on Structures 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!