-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpswplotranges.m
38 lines (37 loc) · 1.78 KB
/
pswplotranges.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function stop = pswplotranges(optimValues,state)
stop = false; % This function does not stop the solver
switch state
case 'init'
nplot = size(optimValues.swarm,2); % Number of dimensions
for i = 1:nplot % Set up axes for plot
subplot(nplot,1,i);
tag = sprintf('psoplotrange_var_%g',i); % Set a tag for the subplot
semilogy(optimValues.iteration,0,'-k','Tag',tag); % Log-scaled plot
ylabel(num2str(i))
end
xlabel('Iteration','interp','none'); % Iteration number at the bottom
subplot(nplot,1,1) % Title at the top
title('Log range of particles by component')
setappdata(gcf,'t0',tic); % Set up a timer to plot only when needed
case 'iter'
nplot = size(optimValues.swarm,2); % Number of dimensions
for i = 1:nplot
subplot(nplot,1,i);
% Calculate the range of the particles at dimension i
irange = max(optimValues.swarm(:,i)) - min(optimValues.swarm(:,i));
tag = sprintf('psoplotrange_var_%g',i);
plotHandle = findobj(get(gca,'Children'),'Tag',tag); % Get the subplot
xdata = plotHandle.XData; % Get the X data from the plot
newX = [xdata optimValues.iteration]; % Add the new iteration
plotHandle.XData = newX; % Put the X data into the plot
ydata = plotHandle.YData; % Get the Y data from the plot
newY = [ydata irange]; % Add the new value
plotHandle.YData = newY; % Put the Y data into the plot
end
if toc(getappdata(gcf,'t0')) > 1/30 % If 1/30 s has passed
drawnow % Show the plot
setappdata(gcf,'t0',tic); % Reset the timer
end
case 'done'
% No cleanup necessary
end