How to arrange data -year to seasonal

2 views (last 30 days)
skyhunt
skyhunt on 24 Dec 2014
Commented: skyhunt on 27 Dec 2014
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

Accepted Answer

Guillaume
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);
  2 Comments
skyhunt
skyhunt on 25 Dec 2014
Thank you sir for your kindly replying.. I have 2001 complete year data..for represent purpose I am not shown here.please reply me sir
skyhunt
skyhunt on 27 Dec 2014
thank you... i have 200 stations like this. how to write for loop for this...plz help me

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!