How to make animation from netcdf file?

3 ビュー (過去 30 日間)
eko supriyadi
eko supriyadi 2017 年 9 月 2 日
コメント済み: eko supriyadi 2017 年 9 月 4 日
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.. :)
netcdf file can be download here: Netcdf file

採用された回答

KSSV
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
  1 件のコメント
eko supriyadi
eko supriyadi 2017 年 9 月 4 日
Siva you are my hero.. tks for your help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by