ocean current velocity data m_quiver plot on high resolution coast line refreshdata not working
10 次查看(过去 30 天)
显示 更早的评论
I have u & v ocean current forecast velocity data and I need to plot every three hours in a loop using 8 days worth of data, then use this plot to create an animated gif. If I loop the map projection its very slow but works. So I was hoping to only refresh the plot data but refreshdata is either not working or more likely than not, I am not using it correctly. Could someone please review my code and see what I am doing wrong or please point me in the right direction. I updated my code with the suggestion below and was still unable to get it to work
This animated gif below is what I am aiming to accomplish with some more efficient code. Right now its super slow because it loops the code that creates the map and axis with the high resolution coastline (the coastline slows this down significantly) and m_quiver plot each iteration.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152802/image.gif)
get_vel_data
global start_stamp
global tstamp
t = datenum(DateTime, 'yyyy-mm-ddTHH:MM:SSZ');
t = datetime(t,'ConvertFrom','datenum','Format', 'yyyy-MM-dd HH:mm:ss');
% start = '2015-11-14 00:00:00';
start = datetime('2015-12-01 00:00:00', 'Format', 'yyyy-MM-dd HH:mm:ss');
start_stamp = datestr(start);
ds = dataset(t,Lat,Lon,u_vel,v_vel);
%%Animated Plot
figure(99)
filename = 'testnew72.gif';
% set map and grid
axes('Position',[0.1,0.1,0.8,0.8]);
m_proj('albers equal-area','lat',[50 65],'lon',[185 215]);
m_gshhs_h('patch',[.6 .6 .6]);
m_grid('linest','none','linewidth',2,'tickdir','out','xaxisloc','top','yaxisloc','right');
tiHan = title(['U and V Ocean Current Velocity Forecast Data Downloaded on ',start_stamp], 'Interpreter', 'none','FontWeight','bold','FontSize',8);
% axis x, y value of title position
tiPos = get (tiHan, 'position');
xyrange = axis;
% move title up
set(tiHan, 'position', tiPos + [0 0.05 * (xyrange(4) - xyrange(3)) 0]);
% so Title doesn't move on zoom.
set(tiHan, 'units', 'inches');
xlabel(['Forecast Data for ',tstamp], 'Interpreter', 'none','FontWeight','bold','FontSize',8);
hold on;
lat = 0;
lon = 0;
u = 0;
v = 0;
uv_plot = m_quiver(lon,lat,u,v);
% looping through the 64 different time frames. 24hrs/(3hr fcasts)*8days=64
for n = 1:64
if n==1;
i=0;
else
i=i+3;
end
% update timestamp for axis label
tstamp = start + hours(i);
tstamp = datestr(tstamp);
% uv_plot.UDataSource = 'u';
% uv_plot.VDataSource = 'v';
% uv_plot.XDataSource = 'lat';
% uv_plot.YDataSource = 'lon';
% xlabel([], 'Interpreter', 'none','FontWeight','bold','FontSize',8);
% update temp dataset
t0 = ds(ds.t == start + hours(i),{'t','Lat','Lon','u_vel','v_vel'});
lat = t0.Lat;
lon = t0.Lon;
u = t0.u_vel;
v = t0.v_vel;
uv_plot.UData = 'u';
uv_plot.VData = 'v';
uv_plot.XData = 'lat';
uv_plot.YData = 'lon';
drawnow()
xlabel(['Forecast Data for ',tstamp], 'Interpreter', 'none','FontWeight','bold','FontSize',8);
% clf;
frame = getframe(99);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if n == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
0 个评论
回答(2 个)
Walter Roberson
2015-12-21
Instead of refreshdata() in the loop, use
t0 = ds(ds.t == start + hours(i),{'t','Lat','Lon','u_vel','v_vel'});
lat = t0.Lat;
lon = t0.Lon;
u = t0.u_vel;
v = t0.v_vel;
uv_plot.UData = U;
uv_plot.VData = v;
uv_plot.XData = lat;
uv_plot.YData = lon;
and the drawnow() will do the update.
refreshdata() is slower than setting the parameters to their desired values.
You also do not need the
xlabel([], 'Interpreter', 'none','FontWeight','bold','FontSize',8);
as you change the xlabel again a few lines later.
11 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!