Filter löschen
Filter löschen

put year in column, months in rows, corresponding months data in rows how in matlab

1 Ansicht (letzte 30 Tage)
I got an output file in Matlab 2014. It contain 3 columns. i like to process it further. 1st column is year (1951-2014) 2nd column is corresponding years months; but in numeric; i.e 1, 2 ....12. 3rd column is data of corresponding months.
Now I want to convert this output file like following way
Year Jan Feb March April May June July August Sept Oct Nov Dec
1951 data data data..........................
... ...
2014 ......................................................
So, my question is how can I do this Matlab code? Any code clue?

Antworten (1)

Walter Roberson
Walter Roberson am 21 Sep. 2015
read (or store) the data into a matrix, say YMData
minyear = min(YMData(:,1))
datatable = accumarray([YMData(:,1)-minyear+1), YMData(:,2)], YMData(:,3), [], [], nan);
numrow = size(datatable, 1);
year_and_data = [(minyear + (0:numrow-1).'), datatable]; %prefix with year
labels = {'Year', 'Jan', 'Feb', 'Mar', 'April', 'May', 'June', 'July', 'August', 'Sep', 'Oct', 'Nov', 'Dec'};
fmt = ['%4s', repmat(' %6s', 1, 12), '\n'];
fprintf(fmt, labels{:});
fmt = ['%4d', repmat(' %6.2f', 1, 12), '\n');
fprintf(fmt, year_and_data.' );

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by