-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodePlotter.m
91 lines (87 loc) · 3.16 KB
/
odePlotter.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function status = odePlotter(~,y,flag,varargin)
persistent TARGET_FIGURE TARGET_AXES N axesData
status = 0;
m = size(y,2);
if nargin < 3 || isempty(flag)
flag = '';
elseif isstring(flag) && isscalar(flag)
flag = char(flag);
end
switch(flag)
case ''
% Check if TARGET_FIGURE and TARGET_AXES is there
if isempty(TARGET_FIGURE) || isempty(TARGET_AXES)
error(message('odePlotter not called with Init'));
elseif ishghandle(TARGET_FIGURE) && ishghandle(TARGET_AXES)
minx = min(y(1:N,:),[],'all');
maxx = max(y(1:N,:),[],'all');
miny = min(y(N+1:2*N,:),[],'all');
maxy = max(y(N+1:2*N,:),[],'all');
if axesData(1,1) > minx
axesData(1,1) = minx;
end
if axesData(1,2) < maxx
axesData(1,2) = maxx;
end
if axesData(2,1) > miny
axesData(2,1) = miny;
end
if axesData(2,2) < maxy
axesData(2,2) = maxy;
end
set(TARGET_AXES,'XLim',axesData(1,:));
set(TARGET_AXES,'YLim',axesData(2,:));
try
if m~= 1
for k = 1:m
ud = get(TARGET_FIGURE,'UserData');
ud.ScatterPoints.XData = y(1:N,k);
ud.ScatterPoints.YData = y(N+1:2*N,k);
ud.ScatterPoints.CData = mod(y(2*N+1:end,k),2*pi);
%pause(0.005);
drawnow update
end
else
ud = get(TARGET_FIGURE,'UserData');
ud.ScatterPoints.XData = y(1:N,1);
ud.ScatterPoints.YData = y(N+1:2*N,1);
ud.ScatterPoints.CData = mod(y(2*N+1:end,1),2*pi);
% currentXLim = get(TARGET_AXES,'XLim');
% currentYLim = get(TARGET_AXES,'YLim');
drawnow update
% for faster updating
% drawnow limirate
end
catch ME
error(message('ErrorUpdatingWindow',ME.message));
end
end
case 'init'
f = figure(gcf);
TARGET_FIGURE = f;
TARGET_AXES = gca;
N = length(y)/3;
ud = get(f,'UserData');
colormap('hsv');
if ~ishold || ~isfield(ud,'ScatterPoints') || ~isfield(ud,'ColorBar')
ud.ScatterPoints = scatter(y(1:N,1),y(N+1:2*N,1),[],y(2*N+1:end,1));
%colorbar;
end
set(TARGET_AXES,'DataAspectRatio',[1 1 1]);
set(TARGET_FIGURE,'Colormap',hsv);
set(TARGET_AXES,'CLim',[0 2*pi]);
set(TARGET_AXES,'Box','on');
axesData = zeros(2,2);
% This second of the code may be unnecessary
% axesData(1,:) = get(TARGET_AXES,'XLim');
% axesData(2,:) = get(TARGET_AXES,'YLim');
%%%%%%%%%%%%%% end
colorbar;
set(f,'UserData',ud);
drawnow update
case 'done'
if ~isempty(y)
scatter(y(1:N,1),y(N+1:2*N,1),[],y(2*N+1:end,1));
end
end
end