Hi Folks
I have a data in which time axis set in following format
ncdisp('myfile.nc')
time
Size: 39x1
Dimensions: time
Datatype: single
Attributes:
standard_name = 'time'
long_name = 'time'
units = 'months since 1970-01-01 00:00:00'
axis = 'T'
climatology = 'climatology_bounds'
year=ncread('myfile.nc','time')
year=
9×1 single column vector
6
18
30
42
54
66
78
90
102
114
126
138
150
162
174
186
198
210
222
234
246
258
270
282
294
306
318
330
342
354
366
378
390
402
414
426
438
450
462
But i want to convert variable year(6,18,30,...,462) to year(1:39), which represent 1 as 1970 and 39 as 2008;
I mean
year(1)=1970
year(2)=1971
.
.
.
year(39)=2008
Could you please suggest me, how can I make it ?
Thanks in advance

 채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 20일

0 개 추천

ncmon = ncread('myfile.nc','time');
year = 1970 + floor((ncmon - 1) / 12);

댓글 수: 3

Abhishek Savita
Abhishek Savita 2017년 12월 20일
편집: Walter Roberson 2017년 12월 20일
Hi James and walter thank you for your reply; I am doing following steps in the matlab to store my data variable time in year(6 18,30,...) to year(1970,1971...)
ncdisp('myfile.nc');
time
Size: 39x1
Dimensions: time
Datatype: single
Attributes:
standard_name = 'time'
long_name = 'time'
units = 'months since 1970-01-01 00:00:00'
axis = 'T'
climatology = 'climatology_bounds'
h18_hc
Size: 360x180x1x39
Dimensions: lon,lat,depth,time
Datatype: single
Attributes:
year=ncread('myfile.nc','time');
ohc=ncread('myfile.nc','h18_hc'
whos year
Name Size Bytes Class Attributes
year 39x1 156 single
whos h18_hc
Name Size Bytes Class Attributes
h18_hc 360x180x1x39 20217600 double
year =
39×1 single column vector
6
18
30
42
54
66
78
90
102
114
126
138
150
162
174
186
198
210
222
234
246
258
270
282
294
306
318
330
342
354
366
378
390
402
414
426
438
450
462
year_new=1970+floor((year-1)/12);
year_new=double(year_new)
ohc_18_new=h18_hc(:,:,:,year_new);
Whem am I doing this i am getting following error
Index exceeds matrix dimensions.
I hope i will get some solution from you, I am very new in matlab.
Thanks in advance
ncmon = ncread('myfile.nc','time');
year_index = 1 + floor((ncmon - 1) / 12);
calendar_year = 1970 + year_index - 1;
ohc_18_new=h18_hc(:,:,:,year_index);
Abhishek Savita
Abhishek Savita 2017년 12월 20일
Thank you very much Walter, it is now.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Knowles
James Knowles 2017년 12월 20일

0 개 추천

I am sure there is a more elegant and simpler solution out there but this will function as you desire.
year = [6
18
30
42
54
66
78
90
102
114
126
138
150
162
174
186
198
210
222
234
246
258
270
282
294
306
318
330
342
354
366
378
390
402
414
426
438
450
462];
YEAR = zeros(39,1); %this will become the vector you desire
for i=1:39
years_passed = floor(year(i)/12);
YEAR(i) = 1970+years_passed;
end

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

질문:

2017년 12월 15일

댓글:

2017년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by