Computer tools > Matlab

Matlab

Summary

Example.m

x = 0:pi/100:2*pi;
y = sin(x);
figure
plot(x,y)

Video_from_figures.m

clear all;
close all;

% Video of results. Requires 4 figures:
% Images/image-file1.fig, ..., Images/image-file4.fig
% Adapted from Matlab tutorial
nFrames = 4;
nFrames_wait=10;
ntimes=3;

dir='Images/';
file_name='image-file';

% Preallocate movie structure.
mov(1:nFrames*ntimes+nFrames_wait) = struct('cdata', [], 'colormap', []);
%axis tight
%set(gca,'nextplot','replacechildren');

for k = 1:nFrames
	open ([dir, file_name, num2str(k), '.fig']);
	mov((k-1)*ntimes+1:k*ntimes) = getframe(gcf);
end

mov(nFrames*ntimes+1:nFrames*ntimes+nFrames_wait) = getframe(gcf);

movie2avi(mov, [strrep(file_name,'-','_'),'.avi'], 'compression', 'None');

UI_control.m

To create a slider like on the following figure.
function ex_uicontrol
    % Example code for uicontrol reference page
    % Creates a slider. Found on Matlab tutorial

    % Create a figure and an axes to contain a 3-D surface plot.
    figure;
    hax = axes('Units','pixels');
    surf(peaks);

     % Create a uicontrol object to let users change the colormap
    uicontrol('Style', 'slider',...
        'Min',1,'Max',50,'Value',41,...
        'Position', [400 20 120 20],...
        'Callback', {@surfzlim,hax});   % Slider function handle callback
                                        % Implemented as a subfunction
       % Add a text uicontrol to label the slider.
    uicontrol('Style','text',...
        'Position',[400 45 120 20],...
        'String','Vertical Exaggeration')

end

function surfzlim(hObj,event,ax) %#ok
    % Called to set zlim of surface in figure axes
    % when user moves the slider control 
    val = get(hObj,'Value');
    surf(val*peaks);
    zlim(ax,'auto');%[-val val]);
end