@@ -64,6 +64,8 @@ function plot_field(ax,simulation,component,fieldType,GIFoutputname)
64
64
E = simulation .output .initialField ;
65
65
end
66
66
67
+ cmap = interp1(1 : 3 ,[0 0 1 ; 1 1 1 ; 1 0 0 ],linspace(1 ,3 ,256 )); % define a diverging colormap
68
+
67
69
switch lower(component )
68
70
case ' real ex'
69
71
fld = reshape(gather(E(: ,1 )), dims );
@@ -73,18 +75,11 @@ function plot_field(ax,simulation,component,fieldType,GIFoutputname)
73
75
fld = reshape(gather(E(: ,3 )), dims );
74
76
case ' abs e'
75
77
fld = reshape(gather(sqrt(sum(abs(E ).^2 ,2 ))), dims );
78
+ cmap = parula(256 ); % use default (sequential) colormap for abs(E)
76
79
end
77
80
78
- if exist(' GIFoutputname' ,' var' )
79
- t = linspace(0 ,2 * pi ,26 ); t(end ) = []; % 25 frames
80
- cmap = interp1(1 : 3 ,[0 0 1 ; 1 1 1 ; 1 0 0 ],linspace(1 ,3 ,256 - 32 ));
81
- gifcmap = [cmap ; gray(32 )]; % add some grayscale colors for the gif colormap
82
- caxislim = [-max(abs(fld(: ))), max(abs(fld(: )))];
83
- else
84
- t = 0 ;
85
- cmap = parula(256 );
86
- caxislim = [0 , max(abs(fld(: )))];
87
- end
81
+ % define axis limits: lower limit should be 0 for abs(E) and -max(abs(E)) for real(Ei)
82
+ caxislim = [-max(abs(fld(: )))*min(0 , min(real(fld(: ))))/min(real(fld(: ))) , max(abs(fld(: )))];
88
83
89
84
fldPnts = reshape([simulation .output .fieldPoints(: ,1 ), ...
90
85
simulation .output .fieldPoints(: ,2 ), ...
@@ -108,10 +103,15 @@ function plot_field(ax,simulation,component,fieldType,GIFoutputname)
108
103
idx = find(dist < rArr ); % find particles intersecting the plane
109
104
rArr(idx ) = sqrt(rArr(idx ).^2 - dist(idx ).^2 ); % overwrite radius of the intersection circle
110
105
111
- if exist(' GIFoutputname' ,' var' ) % initialize imind array
106
+ if exist(' GIFoutputname' ,' var' )
107
+ t = linspace(0 ,2 * pi ,26 ); t(end ) = []; % 25 frames
108
+ cmap = interp1(1 : 3 ,[0 0 1 ; 1 1 1 ; 1 0 0 ],linspace(1 ,3 ,256 - 32 ));
109
+ gifcmap = [cmap ; gray(32 )]; % tweak gif colormap to add some grayscale colors
112
110
f = getframe(gcf );
113
- imind = rgb2ind(f .cdata ,gifcmap ,' nodither' );
111
+ imind = rgb2ind(f .cdata ,gifcmap ,' nodither' ); % initialize imind array
114
112
imind(1 ,1 ,1 ,numel(t )) = 0 ;
113
+ else % no gif to be created
114
+ t = 0 ;
115
115
end
116
116
117
117
for ti= 1 : numel(t )
0 commit comments