フィルターのクリア

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

1 回表示 (過去 30 日間)
Md Shamim Shams
Md Shamim Shams 2015 年 9 月 21 日
回答済み: Walter Roberson 2015 年 9 月 21 日
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?

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 9 月 21 日
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.' );

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by