MATLAB Answers

How to make animation from netcdf file?

조회 수: 14(최근 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개)

Community Treasure Hunt

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

Start Hunting!

Translated by