编程语言
首页 > 编程语言> > 【图像处理】基于matlab GIF生成【含Matlab源码 623期】

【图像处理】基于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)

三、运行结果

在这里插入图片描述

四、备注

版本:2014a

标签:623,plot,phi,GIF,源码,m1,dx,dy,pi
来源: https://blog.51cto.com/u_15287606/2977596