How to make animation from netcdf file?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
KSSV
2017-9-4
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
更多回答(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!