diff +anim/setup_surf_plot.m @ 0:48b6fb693025

Initial commit.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 17 Sep 2015 10:12:50 +0200
parents
children f87003695677
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+anim/setup_surf_plot.m	Thu Sep 17 10:12:50 2015 +0200
@@ -0,0 +1,30 @@
+function [update_data,figure_handle] = setup_2d_plot(x,y,z_lim,zfun)
+    default_arg('zfun',@(z)z);
+
+    Z = zeros(length(y),length(x));
+    figure_handle = figure;
+    plot_handle = surf(x,y,Z);
+    plot_handle.LineStyle = 'none';
+    axis_handle = gca;
+
+    xlabel('x')
+    ylabel('y')
+    xlim([x(1) x(end)]);
+    ylim([y(1) y(end)]);
+    zlim(z_lim);
+    caxis(z_lim);
+    % axis vis3d
+    % colormap(parula(256))
+    % colorbar
+
+    function update(t,z)
+        Z = zfun(z);
+        % Z = reshape(zfun(z),length(x),length(y));
+        if ishandle(plot_handle) && ishandle(axis_handle)
+            set(plot_handle,'ZData',Z)
+            title(axis_handle,sprintf('T=%.3f',t));
+            drawnow
+        end
+    end
+    update_data = @update;
+end