1 |
function h=numnodes(fem_grid_struct,ps) |
---|
2 |
%NUMNODES number nodes on current axes. |
---|
3 |
% |
---|
4 |
% INPUT : fem_grid_struct - (from LOADGRID, see FEM_GRID_STRUCT) |
---|
5 |
% ps - point size for screen text numbers |
---|
6 |
% (optional, def=15) |
---|
7 |
% |
---|
8 |
% OUTPUT : h - vector of handle to text objects drawn (optional) |
---|
9 |
% |
---|
10 |
% CALL : h=numnodes(fem_grid_struct,ps); |
---|
11 |
% |
---|
12 |
% Written by : Brian O. Blanton |
---|
13 |
% Summer 1997 |
---|
14 |
% |
---|
15 |
|
---|
16 |
% DEFINE ERROR STRINGS |
---|
17 |
err1=['Not enough input arguments; need atleast x,y']; |
---|
18 |
err2=['Too many input arguments; type "help numnodes"']; |
---|
19 |
warn1=['The current axes is too dense for the ' |
---|
20 |
'node numbers to be readable. CONTINUE?']; |
---|
21 |
|
---|
22 |
% check arguments |
---|
23 |
if nargin ==0 |
---|
24 |
error(err1); |
---|
25 |
elseif nargin >2 |
---|
26 |
error(err2); |
---|
27 |
elseif nargin==1 |
---|
28 |
ps=15; |
---|
29 |
end |
---|
30 |
|
---|
31 |
if ~is_valid_struct(fem_grid_struct) |
---|
32 |
error(' Argument to NUMNODES must be a valid fem_grid_struct.') |
---|
33 |
end |
---|
34 |
|
---|
35 |
% Extract grid fields from fem_grid_struct |
---|
36 |
% |
---|
37 |
elems=fem_grid_struct.e; |
---|
38 |
x=fem_grid_struct.x; |
---|
39 |
y=fem_grid_struct.y; |
---|
40 |
|
---|
41 |
X=get(gca,'Xlim'); |
---|
42 |
Y=get(gca,'YLim'); |
---|
43 |
|
---|
44 |
% get indices of nodes within viewing window defined by X,Y |
---|
45 |
filt=find(x>=X(1)&x<=X(2)&y>=Y(1)&y<=Y(2)); |
---|
46 |
|
---|
47 |
% determine if viewing window is zoomed-in enough for node |
---|
48 |
% numbers to be meaningful; |
---|
49 |
set(gca,'Units','points'); |
---|
50 |
rect=get(gca,'Position'); % get viewing window width in point units (1/72 inches) |
---|
51 |
set(gca,'Units','normalized'); |
---|
52 |
xr=rect(3)-rect(1); |
---|
53 |
yr=rect(4)-rect(2);; |
---|
54 |
xden=xr/sqrt(length(filt)); |
---|
55 |
yden=yr/sqrt(length(filt)); |
---|
56 |
den=sqrt(xden*xden+yden*yden); |
---|
57 |
if den < 5*ps |
---|
58 |
click=questdlg(warn1,'Continue??','Yes','No','Cancel','No'); |
---|
59 |
if strcmp(click,'No')|strcmp(click,'Cancel'), |
---|
60 |
if nargout==1,h=[];,end |
---|
61 |
return |
---|
62 |
end |
---|
63 |
end |
---|
64 |
|
---|
65 |
% Build string matrix |
---|
66 |
strlist=num2str(filt,6); |
---|
67 |
|
---|
68 |
xx=x(filt);yy=y(filt); |
---|
69 |
format long e |
---|
70 |
% label only those nodes that lie within viewing window. |
---|
71 |
htext=text(xx,yy,strlist,... |
---|
72 |
'FontSize',ps,... |
---|
73 |
'HorizontalAlignment','center',... |
---|
74 |
'VerticalAlignment','middle',... |
---|
75 |
'Color','k',... |
---|
76 |
'Tag','Node #'); |
---|
77 |
|
---|
78 |
|
---|
79 |
if nargout==1,h=htext;,end |
---|
80 |
return |
---|
81 |
% |
---|
82 |
% Brian O. Blanton |
---|
83 |
% Department of Marine Sciences |
---|
84 |
% 15-1A Venable Hall |
---|
85 |
% CB# 3300 |
---|
86 |
% Uni. of North Carolina |
---|
87 |
% Chapel Hill, NC |
---|
88 |
% 27599-3300 |
---|
89 |
% |
---|
90 |
% 919-962-4466 |
---|
91 |
% blanton@marine.unc.edu |
---|
92 |
% |
---|
93 |
% Summer 1997 |
---|
94 |
% |
---|
95 |
|
---|
96 |
|
---|