Extracting temperature data from netCDF file and then trying to take time derivative of temperature
1 次查看(过去 30 天)
显示 更早的评论
I am trying to extract temperature data from a netCDF file:
SATh = ncread('spatially_int_Historical.nc','A_sat');
SATFAST = ncread('spatially_int_1000GT_FAST.nc','A_sat');
Then I want to calculate the temperature anomaly (w.r.t. the first i value, year 1800):
for i=1,200
SATdiffhist(i) = SATh(i) - SATh(1);
i = i+1
end
for i=1,1000
SATdiffFAST(i) = SATFAST(i) - SATh(1);
i = i+1
end
Finally, the goal is to calculate the time derivative of the temperature anomaly:
deltaSATdiffFAST(1) = SATdiffFAST(1) - SATdiffhist(200);
for i=2,1000
deltaSATdiffFAST(i) = SATdiffFAST(i) - SATdiffFAST(i-1)
i = i+1
end
deltaSATdiffVFAST(1) = SATdiffVFAST(1) - SATdiffhist(200);
for i=2,1000
deltaSATdiffVFAST(i) = SATdiffVFAST(i) - SATdiffVFAST(i-1);
i = i+1
end
The problem seems to arise from the fact that the original temperature data (SATh and SATFAST) are not referenced to an i-value, so the for loops only iterate once.
Is there a way to rectify this?
0 个评论
回答(1 个)
per isakson
2013-7-11
for i=1,200
SATdiffhist(i) = SATh(i) - SATh(1);
i = i+1
end
with Matlab syntax
for i=1:200
SATdiffhist(i) = SATh(i) - SATh(1);
end
However,
SATdiffhist = SATh - SATh(1);
is faster
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!