Error when generating a gif

2 ビュー (過去 30 日間)
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2023 年 1 月 31 日
I'm having a problem generating a gif from a netcdf file.
I am using the script below that I took as a reference in the following link:https://la.mathworks.com/matlabcentral/answers/354954-how-to-make-animation-from-netcdf-file
the google drive link with the netcdf file I used is this: https://drive.google.com/drive/folders/1G8Oj88iqk0g71WLe-p0Q1WN6G5wwGZoq?usp=sharing
the error is in the "surf" command, I don't know how to solve it, does anyone have an idea?
%% script
file = 'data_chirps.2020.12.nc' ;
lon = ncread(file,'longitude') ;
lat = ncread(file,'latitude') ;
t = ncread(file,'time') ;
precip = ncread(file,'precip') ;
% Make animation
filename = 'test.gif';
for i = 1:length(t)
surf(lon,lat,precip(:,:,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 件のコメント
Walter Roberson
Walter Roberson 2023 年 1 月 31 日
whos lon lat precip
please show us the results

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

採用された回答

Walter Roberson
Walter Roberson 2023 年 1 月 31 日
Reminder: longitude is y data and latitude is x data but surf requires x then y
  1 件のコメント
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2023 年 1 月 31 日
ok, this was the problem, I changed the orders.
thanks!
surf(lat,lon,precip(:,:,i))

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by