Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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?

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Sept. de 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.' );

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by