其他分享
首页 > 其他分享> > [1d粒子模拟] field plot

[1d粒子模拟] field plot

作者:互联网

 

%
% Field plot (Ex,Ey,Ez,By,Bz)
%     xlabel('X');
%     str = {'Ex','Ey','Ez','By','By'};
%     ylabel(str(n))
%
function hdiag = plotfield(hdiag, n, jdiag)
  global prm ren
  global nxp2
  global X1 X2 X2

  global ex ey ez
  global by bz
  global bx0 by0
  
  switch n
   case 1
    f = ex*ren.e;
    m = prm.emax;
   case 2
    f = ey*ren.e;
    m = prm.emax;
   case 3
    f = ez*ren.e;
    m = prm.emax;
   case 4
    f = (by-by0)*ren.b;
    m = prm.bmax;
   case 5
    f = bz*ren.b;
    m = prm.bmax;
  end

  if jdiag == 1
    xx = 0:prm.dx:(prm.nx-1)*ren.x;
    hdiag.plt(hdiag.nplt).hplot(n) = plot(xx, f(X2),'k-','LineWidth',2);
    
    csvwrite('xx_init.csv',xx)
    switch n
        case 1
          csvwrite('Ex.csv',f(X2)');
        case 2
          csvwrite('Ey.csv',f(X2)');
        case 3
          csvwrite('Ez.csv',f(X2)');
        case 4
          csvwrite('By.csv',f(X2)');
        case 5
          csvwrite('Bz.csv',f(X2)');
    end
   
    if m > 0 
      axis([0 (prm.nx-1)*ren.x  -m m]);
    else
      set(gca,'xlim',[0 (prm.nx-1)*ren.x]);
    end
    xlabel('X');
    str = {'Ex','Ey','Ez','By','By'};
    ylabel(str(n))
  else
    %set(hdiag.plt(hdiag.nplt).hplot(n),'ydata',f(X2))  %加快计算速度
    switch n
        case 1
          dlmwrite('Ex.csv',f(X2)','delimiter',',','-append');
        case 2
          dlmwrite('Ey.csv',f(X2)','delimiter',',','-append');
        case 3
          dlmwrite('Ez.csv',f(X2)','delimiter',',','-append');
        case 4
          dlmwrite('By.csv',f(X2)','delimiter',',','-append');
        case 5
          dlmwrite('Bz.csv',f(X2)','delimiter',',','-append');
    end
  end
    
return

标签:case,plot,prm,global,field,ren,1d,X2,csv
来源: https://blog.csdn.net/qq_39154376/article/details/121866413