필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by