Extracting temperature data from netCDF file and then trying to take time derivative of temperature
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
per isakson
on 11 Jul 2013
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 Comments
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!