1 |
function h=plotdrog(x,y,ndrog,tstride,dstride) |
---|
2 |
%PLOTDROG plot drogue .pth file output from DROG3D or DROG3DDT. |
---|
3 |
% PLOTDROG plots the paths of drogue locations as specified |
---|
4 |
% in the x,y coordinate arrays. PLOTDROG takes as required |
---|
5 |
% arguments the x,y coordinates of the drogue locations AND |
---|
6 |
% the number of drogues in the path file. The path information |
---|
7 |
% from DROG3D or DROG3DDT can be read into MATLAB with |
---|
8 |
% READ_PTH, which reads .pth files. |
---|
9 |
% |
---|
10 |
% PLOTDROG draws each drogue with a separate line, solid |
---|
11 |
% by default. Each drogue line is referenced with |
---|
12 |
% one object handle. Therefore, to change the linetype or |
---|
13 |
% color of the lines, use the MATLAB command SET and the handle |
---|
14 |
% returned by PLOTDROG. |
---|
15 |
% |
---|
16 |
% Even though READ_PTH returns the entire path matrix, only |
---|
17 |
% two columns of it are passed to PLOTDROG. It is up to the |
---|
18 |
% user to make sure the correct ones are passed in. I.e., |
---|
19 |
% there is no way for PLOTDROG to ensure x,y represent |
---|
20 |
% HORIZONTAL coordinates, etc. |
---|
21 |
% |
---|
22 |
% INPUT: |
---|
23 |
% x,y - x,y coordinates of drogues |
---|
24 |
% ndrog - number of drogues in path matrix; |
---|
25 |
% this number is returned by READ_PTH |
---|
26 |
% tstride - time stride (optional, def = 1) is |
---|
27 |
% the number of timesteps to skip over. 1 would |
---|
28 |
% mean "plot all timesteps"; 2 would mean "plot |
---|
29 |
% every other timestep"; i.e., skip every other |
---|
30 |
% timestep; etc... |
---|
31 |
% dstride - drogue stride (optional, def = 1) is |
---|
32 |
% the number of drogues to skip; see tstride above. |
---|
33 |
% In order to specify dstride, you must also specify |
---|
34 |
% tstride. |
---|
35 |
% |
---|
36 |
% Both tstride and dstride can be vectors of specific timesteps |
---|
37 |
% or drogue numbers to plot. In order to plot only ONE drogue |
---|
38 |
% or ONE timestep, pass into PLOTDROG the values of tstride |
---|
39 |
% and/or dstride enclosed in {}'s. For example, to |
---|
40 |
% plot the initial drogue locations, call PLOTDROG as: |
---|
41 |
% >> h=plotdrog(x,y,ndrog,{1}); |
---|
42 |
% To plot the 3rd drogue for all timesteps, call PLOTDROG as: |
---|
43 |
% >> h=plotdrog(x,y,ndrog,1,{3}); |
---|
44 |
% |
---|
45 |
% OUTPUT: |
---|
46 |
% h - the handle(s) to the path lines on the current axes |
---|
47 |
% |
---|
48 |
% dstride - the number of drogues to skip, see tstride above. |
---|
49 |
% In order to specify dstride, you must also specify |
---|
50 |
% tstride. |
---|
51 |
% |
---|
52 |
% CALL: h=plotdrog(x,y,ndrog); |
---|
53 |
% h=plotdrog(x,y,ndrog,tstride); |
---|
54 |
% h=plotdrog(x,y,ndrog,tstride,dstride); |
---|
55 |
% |
---|
56 |
% Written by: Brian O. Blanton |
---|
57 |
% |
---|
58 |
|
---|
59 |
% DEFINE ERROR STRINGS |
---|
60 |
err1=['PLOTDROG requires 3, 4, or 5 arguments.']; |
---|
61 |
err2=['tstride argument to PLOTDROG must be a positive integer(s).']; |
---|
62 |
err3=['dstride argument to PLOTDROG must be a positive integer(s).']; |
---|
63 |
err4=['Lengths of x,y to PLOTDROG must be equal.']; |
---|
64 |
err5=['Path length inconsistent with number of drogues specified in PLOTDROG']; |
---|
65 |
err6=['ndrog argument to PLOTDROG must be a positive integer.']; |
---|
66 |
err7=['tstride argument to PLOTDROG must be less than number of timesteps.']; |
---|
67 |
err8=['dstride argument to PLOTDROG must be less than number of drogs.']; |
---|
68 |
err9=['Cell argument tstride to PLOTDROG must be of length 1']; |
---|
69 |
err10=['Cell argument dstride to PLOTDROG must be of length 1']; |
---|
70 |
|
---|
71 |
% check arguments |
---|
72 |
if nargin < 3 | nargin > 5,error(err1),end |
---|
73 |
|
---|
74 |
% If we're here, the first 3 required arguments exist. |
---|
75 |
if ndrog<0 | ~isint(ndrog), error(err6),end |
---|
76 |
|
---|
77 |
% Check x,y lengths |
---|
78 |
if length(x)~=length(y),error(err4),end |
---|
79 |
|
---|
80 |
% Make sure length(x)/ndrog is an integer. |
---|
81 |
if ~isint(length(x)/ndrog),error(err5),end |
---|
82 |
|
---|
83 |
% number of timesteps in length(x) |
---|
84 |
nts=length(x)/ndrog; |
---|
85 |
|
---|
86 |
% Check remaining (optional) arguments |
---|
87 |
if nargin>3 |
---|
88 |
% Atleast tstride has been specified. |
---|
89 |
% Is it a cell array? |
---|
90 |
if isa(tstride,'cell') |
---|
91 |
temp=tstride{1}; |
---|
92 |
if length(temp)~=1,error(err9),end |
---|
93 |
tstride=temp; |
---|
94 |
else |
---|
95 |
if length(tstride)==1 |
---|
96 |
if tstride<1 | ~isint(tstride), error(err2),end |
---|
97 |
tstride=1:tstride:nts; |
---|
98 |
else |
---|
99 |
tstride=sort(tstride(:)); |
---|
100 |
if min(tstride)<1 | ~isint(tstride), error(err2),end |
---|
101 |
end |
---|
102 |
end |
---|
103 |
|
---|
104 |
if nargin==5 |
---|
105 |
% Is dstride a cell array? |
---|
106 |
if isa(dstride,'cell') |
---|
107 |
temp=dstride{1}; |
---|
108 |
if length(temp)~=1,error(err9),end |
---|
109 |
dstride=temp; |
---|
110 |
else |
---|
111 |
if length(dstride)==1 |
---|
112 |
if dstride<1 | ~isint(dstride), error(err3),end |
---|
113 |
dstride=1:dstride:ndrog; |
---|
114 |
else |
---|
115 |
dstride=sort(dstride(:)); |
---|
116 |
if min(dstride)<1 | ~isint(dstride), error(err3),end |
---|
117 |
end |
---|
118 |
end |
---|
119 |
else |
---|
120 |
dstride=1:ndrog; |
---|
121 |
end |
---|
122 |
else |
---|
123 |
tstride=1:nts; |
---|
124 |
dstride=1:ndrog; |
---|
125 |
end |
---|
126 |
|
---|
127 |
% Check tstride,dstride against nts,ndrog |
---|
128 |
if max(tstride)>nts,error(err7),end |
---|
129 |
if max(dstride)>ndrog,error(err8),end |
---|
130 |
|
---|
131 |
% reshape x,y into matrices of dimension ndrog x ntimestep |
---|
132 |
X=reshape(x,ndrog,nts)'; |
---|
133 |
Y=reshape(y,ndrog,nts)'; |
---|
134 |
|
---|
135 |
% reduce by tstride |
---|
136 |
X=X(tstride,:); |
---|
137 |
Y=Y(tstride,:); |
---|
138 |
|
---|
139 |
% reduce by dstride |
---|
140 |
X=X(:,dstride); |
---|
141 |
Y=Y(:,dstride); |
---|
142 |
|
---|
143 |
% Add NaN row to bottom of X,Y |
---|
144 |
[m,n]=size(X); |
---|
145 |
NN=NaN*ones(size(1:n)); |
---|
146 |
X=[X;NN]; |
---|
147 |
Y=[Y;NN]; |
---|
148 |
|
---|
149 |
if length(tstride)==1 |
---|
150 |
hout=line(X,Y,'Tag','path','LineStyle','.','Marker','.','Color','r'); |
---|
151 |
else |
---|
152 |
hout=line(X,Y,'Tag','path'); |
---|
153 |
end |
---|
154 |
|
---|
155 |
% Fill output argument if returned. |
---|
156 |
if nargout==1,h=hout;,end |
---|
157 |
|
---|
158 |
% |
---|
159 |
% Brian O. Blanton |
---|
160 |
% Department of Marine Science |
---|
161 |
% 15-1A Venable Hall |
---|
162 |
% CB# 3300 |
---|
163 |
% Uni. of North Carolina |
---|
164 |
% Chapel Hill, NC |
---|
165 |
% 27599-3300 |
---|
166 |
% |
---|
167 |
% 919-962-4466 |
---|
168 |
% blanton@marine.unc.edu |
---|
169 |
% |
---|
170 |
% Summer 1998 |
---|
171 |
% |
---|
172 |
|
---|