
waiter=waitbar(0,'wait'); 

for stdev=1:50
tic
big_electron_dump=[]; 
figure('units','normalized','outerposition',[0 0 1 1]);
contour(pot_grid(1:end,1:end)); shading flat; axis equal; hold on; 
% waitvar2=waitbar(0,'wait'); 
waitcounter=1; 
for ypos=410:10:590


q=1.6E-19; % e- charge in [coulombs]
m_e=9.1E-31; % e- mass in [kg] 
dt=0.05; % note that every time the loop goes through dt, a time of 2*dt passes in realtime 
dt=0.1; 
% electron initial position and velocity [row_pos col_pos row_vel col_vel] 
% min=min_energy; max=100+(100-min); 
% hori_vel=min+(max-min)*rand(); 
temp=normrnd(100,stdev);
if temp>0
hori_vel=temp;
end
electron=[ypos 1 0 hori_vel];
electron_dump=[]; 
electron_pos=zeros(1000); 
hold on; 
% figure; hold on; 
% waiter=waitbar(0, 'wait'); 
steps=350; 
steps=220; 
for t=1:steps
    
    electron(1)=electron(1)+electron(3)*dt;
%     electron(1)=round(electron(1)); 
    electron(2)=electron(2)+electron(4)*dt; 
%     electron(2)=round(electron(2)); 
    
    % E field component only 
if electron(1)<991 && electron(2)<991 && electron(1)>=1 && electron(2)>=1
    electron(3)=electron(3)-EgridY(round(electron(1)), round(electron(2))).*dt; 
    electron(4)=electron(4)-EgridX(round(electron(1)), round(electron(2))).*dt; 
end

    % B field component only 
%     dv_b=cross([electron(3) electron(4) 0], [0, 0, B_grid(electron(1), electron(2))]); 
%     electron(3)=electron(3)+dv_b(1).*0.1*dt;
%     electron(4)=electron(4)+dv_b(2).*0.1*dt; 
    
    % q./m_e.*
%     electron(3)=electron(3)+EgridX(electron(1),electron(2)).*dt;
    %+dv_b(1).*dt;
%     electron(4)=electron(4)+EgridY(electron(1),electron(2)).*dt;
    %+dv_b(2).*dt;
    
    
    plot(electron(2), electron(1),'o','markersize',2); 
electron_dump=[electron_dump; electron];
% electron_pos(electron(1), electron(2))=1; 
   
    axis([0 2000 0 1000]); 
end
big_electron_dump=[big_electron_dump electron_dump]; 
% waitbar(waitcounter/length(410:5:590),waitvar2); 
waitcounter=waitcounter+1; 
end


title(sprintf('%g',stdev)); 

% save the image
saveas(gcf,['einzel_',sprintf('Min energy equals %g',stdev),'.tiff']); 
% img=imread(['wave_',sprintf('%03d',nstep),'.tiff']);
% delete(['wave_',sprintf('%03d',nstep),'.jpeg']);
% img=rgb2gray(img); 
% imwrite(img,['wave_',sprintf('%03d',nstep),'.jpeg']); 
close(gcf); 
waitbar(stdev/100, waiter); 
toc
end


