put year in column, months in rows, corresponding months data in rows how in matlab
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (1)
Walter Roberson
il 21 Set 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.' );
0 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!