-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotseq2.m
56 lines (44 loc) · 1.46 KB
/
plotseq2.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
function [hy,h] = plotseq2(x,stateSeq,hmm)
% PLOTSEQ2 Plot a 2-dimensional sequence together with a state sequence
%
% PLOTSEQ2(X,STATESEQ) plots a two-dimensional sequence X (one observation
% per row) as a 2-dimensional figure. It superposes the corresponding
% state sequence STATESEQ as colored dots on the obesrvations. X and
% STATESEQ must have the same length.
%
% PLOTSEQ2(X,STATESEQ,HMM) adds the "Gaussian ellipsis" corresponding to
% each state of the model stored in the object HMM, where:
% HMM.means = MEANS;
% HMM.vars = VARS;
% HMM.trans = TRANSITIONS
%
if nargin < 3,
hmm = [];
end;
len = size(x,1);
if (len+2) ~= length(stateSeq),
error('The length of the state sequence must be the length of the observation sequence plus 2.');
end;
stateSeq = stateSeq(2:(end-1));
numStates = max(stateSeq);
cmap = hsv(numStates-1);
hy(1) = plot(x(:,1),x(:,2),'y');
washold = ishold; hold on;
%set(gca,'xlim',[0 2500],'ylim',[500 3000],'dataAspectRatio',[1 1 1]);
%set(gca,'dataAspectRatio',[1 1 1]);
for i=2:numStates,
[where] = find(stateSeq ~= i);
copy = x;
copy(where,:) = NaN;
h(i-1,1) = plot(copy(:,1),copy(:,2),'color',cmap(i-1,:), ...
'marker','o','markerface',cmap(i-1,:), 'markerSize', 5, ...
'linestyle','none');
leg{i-1} = ['State ' num2str(i)];
end;
if ~isempty(hmm),
for i=2:(numStates)
plotgaus(hmm.means{i},hmm.vars{i},cmap(i-1,:));
end;
end;
if ~washold, hold off; end;
legend(h,leg);