【图像处理】基于matlab GIF生成【含Matlab源码 623期】

一、简介

基于matlab gif图片的生成

二、源代码

% session 1
% convection and diffusion in 2D!!

% small initialization
clear all
clf
syms x m

% finding am
L = 50;
f = sin(pi*x*m/L);
a1 = 2/L*int(x*f,x,[0,1]);
a2 = 2/L*int((2-x)*f,x,[1,2]); 
am = a1 + a2;

% from sym2double
clear x 
m1 = 1:100;
am1 = double(subs(am,m,m1));

% space discretization
dx = -2:0.25:10;
dy = 1:20;
[xx,yy] = meshgrid(dx,dy);

% preallocation
phi = zeros(1,size(dx,2));
phi2D = zeros(size(dy,2),size(dx,2));

% time loop
for t = 0:0.1:10
    clf
    n = 1;
    
    % calculate phi
    for x = dx
        % convection (comment if other option used)
        % phi(n) = sum(am1.*sin(m1*pi*(x-t)/L));
        
        % diffusion (comment if other option used)
        % phi(n) = sum(am1.*exp(-0.1*(m1*pi/L).^2*t).*sin(m1*pi*(x)/L));
        
        % convection & diffusion (comment if other option used)
        phi(n) = sum(am1.*exp(-0.1*(m1*pi/L).^2*t).*sin(m1*pi*(x-t)/L));
        n = n+1;
    end
    
    % create phi matrix
    for y = dy
        phi2D(y,:) = phi;
    end
    
    % plot 1D line (comment if plot 2D is used)
    % plot(dx,phi)   
    % axis([min(dx) max(dx) -1 1])
    
    % plot 2D surface (comment if plot 1D is used)
    surface(xx,yy,phi2D)
    axis([min(dx) max(dx) min(dy) max(dy) -1 1])
    
    % some other plot options
    title(sprintf('Simulation time = %f s', t))
    xlabel('x'); ylabel('y'); zlabel('z')
    grid on
    rotate3d on
    % view(0,90) % view from above
    view(3)
    pause(0.01)

三、运行结果

【图像处理】基于matlab GIF生成【含Matlab源码 623期】

四、备注

版本:2014a

上一篇:RSA密码算法C++实现


下一篇:机敏问答[常微][1] #20210611