How to make animation from netcdf file?
3 views (last 30 days)
Show older comments
Hi all,
Now, i have success make contour from netcdf file.. and now i want create animation from this netcdf.. teach me how i can do it with fluent.
as example may be you can continue this script:
ncid=netcdf.open('sst2016b.nc','write');
lon=ncread('sst2016b.nc','longitude');
lat=ncread('sst2016b.nc','latitude');
time=ncread('sst2016b.nc','time');
lat=double(lat);
lon=double(lon);
time=double(time);
waktu=(time)/24+datenum('1900-01-01 00:00:00');
suhu=netcdf.getVar(ncid,3, [0 0 0],[25 25 31]); % from here i want make animation
suhu=double(suhu);
scale=netcdf.getAtt(ncid,3,'scale_factor');
offset=netcdf.getAtt(ncid,3,'add_offset');
suhub=suhu*scale+offset;
suhub=double(suhub);
[X,Y]=meshgrid(lat,lon);
%Z=griddata(lon,lat,suhub,Y,X); % i'm sorry i'm also stuck here, because suhub have matrix 25*25*31 while griddata can't workly when dimension matrix greater than two
%s=pcolor(lon,lat,Z);
%shading interp;
% from reference, after the above script we must do looping function.. correct if i'm wrong..
% are i'm right we must use set command?
% i'm confuse what different drawnow and pause command?
so, i want sst contour is change respect to time
tks for your help.. :)
0 Comments
Accepted Answer
KSSV
on 4 Sep 2017
file = 'sst2016b.nc' ;
lon = ncread(file,'longitude') ;
lat = ncread(file,'latitude') ;
t = ncread(file,'time') ;
sst = ncread(file,'sst') ;
% Make animation
filename = 'test.gif';
for i = 1:length(t)
surf(lon,lat,sst(:,:,i))
shading interp
view(2)
drawnow
% Capture the plot as an image
frame = getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if i == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
More Answers (0)
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!