⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clabel.m

📁 m_map是加拿大学者编写的一个在matlab上绘地图的软件
💻 M
📖 第 1 页 / 共 2 页
字号:
    Ir=sum( d(ones(1,lp),:)' < psn(ones(1,l),:)+len_lab );     Ir = max(0,min(Ir,length(d)-1));    Il = max(0,min(Il,length(d)-1));    Ic = max(0,min(Ic,length(d)-1));    % Endpoints of text in data coordinates    wl=(d(Il+1)-psn+len_lab)./(d(Il+1)-d(Il));    wr=(psn-len_lab-d(Il)  )./(d(Il+1)-d(Il));    xl=x(Il).*wl+x(Il+1).*wr;    yl=y(Il).*wl+y(Il+1).*wr;       wl=(d(Ir+1)-psn-len_lab)./(d(Ir+1)-d(Ir));    wr=(psn+len_lab-d(Ir)  )./(d(Ir+1)-d(Ir));    xr=x(Ir).*wl+x(Ir+1).*wr;    yr=y(Ir).*wl+y(Ir+1).*wr;       trot=atan2( (yr-yl)*YDir*Aspy, (xr-xl)*XDir*Aspx )*180/pi; %% EF 4/97    backang=abs(trot)>90;    trot(backang)=trot(backang)+180;        % Text location in data coordinates     wl=(d(Ic+1)-psn)./(d(Ic+1)-d(Ic));    wr=(psn-d(Ic)  )./(d(Ic+1)-d(Ic));        xc=x(Ic).*wl+x(Ic+1).*wr;    yc=y(Ic).*wl+y(Ic+1).*wr;    % Shift label over a little if in a curvy area    shiftfrac=.5;        xc=xc*(1-shiftfrac)+(xr+xl)/2*shiftfrac;    yc=yc*(1-shiftfrac)+(yr+yl)/2*shiftfrac;        % Remove data points under the label...    % First, find endpoint locations as distances along lines      dr=d(Ir)+sqrt( ((xr-x(Ir))*Aspx).^2 + ((yr-y(Ir))*Aspy).^2 );    dl=d(Il)+sqrt( ((xl-x(Il))*Aspx).^2 + ((yl-y(Il))*Aspy).^2 );      % Now, remove the data points in those gaps using that    % ole' Matlab magic. We use the sparse array stuff instead of    % something like:      %        f1=zeros(1,l); f1(Il)=ones(1,lp);    % because the sparse functions will sum into repeated indices,    % rather than just take the last accessed element - compare    %   x=[0 0 0]; x([2 2])=[1 1]    % with    %   x=full(sparse([1 1],[2 2],[1 1],1,3))    % (bug fix in original code 18/7/95 - RP)    f1=full(sparse(ones(1,lp),Il,ones(1,lp),1,l));    f2=full(sparse(ones(1,lp),Ir,ones(1,lp),1,l));    irem=find(cumsum(f1)-cumsum(f2))+1;    x(irem)=[];    y(irem)=[];    d(irem)=[];    l=l-size(irem,2);        % Put the points in the correct order...        xf=[x(1:l),xl,repmat(NaN,size(xc)),xr];    yf=[y(1:l),yl,yc,yr];    [df,If]=sort([d(1:l),dl,psn,dr]);      % ...and draw.    %    % Here's where we assume the order of the h(k).      %    z = get(h(k),'zdata');    if ~isfilled, % Only modify lines or patches if unfilled      set(h(k),'xdata',[xf(If) NaN],'ydata',[yf(If) NaN])      % Handle contour3 case (z won't be empty).      if ~isempty(z), z = repmat(z(1),size(get(h(k),'xdata'))); end      if strcmp(get(h(k),'type'),'patch')        set(h(k),'cdata',lvl+[0*xf(If) 0])      end    end    for jj=1:lp,      % Handle contour3 case (z won't be empty).      if ~isempty(z),        H = [H;text(xc(jj),yc(jj),z(1),lab,'rotation',trot(jj), ...             'verticalAlignment','middle','horizontalAlignment','center',...             'clipping','on','userdata',lvl,varargin{:})];      else        H = [H;text(xc(jj),yc(jj),lab,'rotation',trot(jj), ...             'verticalAlignment','middle','horizontalAlignment','center',...             'clipping','on','userdata',lvl,varargin{:})];             end    end;  else    if ~isfilled, % Only modify lines or patches if unfilled      %      % Here's another place where we assume the order of the h(k)       %      set(h(k),'xdata',[x NaN],'ydata',[y NaN], ...               'zdata',[0*x 0])      if strcmp(get(h(k),'type'),'patch')         set(h(k),'cdata',lvl+[0*x 0])      end    end  end;    if ~manual    ii=ii+1+CS(2,ii);  endend;  % delete dummy stringdelete(H1);%-------------------------------------------------------%-------------------------------------------------------function h = plus_labels(threeD,cs,varargin);%% Draw the labels as plus symbols next to text (v4 compatible)%%    RP - 14/5/97%    Clay M. Thompson 6-7-96%    Charles R. Denham, MathWorks, 1988, 1989, 1990.cax = gca;manual = 0;choice = 0;if nargin > 2  if isstr(varargin{1}),    if strcmp(varargin{1}, 'manual')      varargin(1)=[];      manual=1;    end;  else    choice = 1;    v = sort(varargin{1}(:));    varargin(1)=[];  endend[mcs, ncs] = size(cs);% Find range of levels.k = 1; i = 1;while k <= ncs   levels(i) = cs(1,k);   i = i + 1;   k = k + cs(2,k) + 1;endcmin = min(levels);cmax = max(levels);crange = max(abs(levels));cdelta = abs(diff(levels)); cdelta = min(cdelta(cdelta > eps))/max(eps,crange); % Minimum significant changeif isempty(cdelta), cdelta = 0; end% Decompose contour data structure if manual mode.if manual   disp(' '), disp('    Please wait a moment...')   x = []; y = []; clist = []; k = 0; n = 0;   while (1)      k = k + n + 1; if k > ncs, break, end      c = cs(1,k); n = cs(2,k); nn = 2 .* n -1;      xtemp = zeros(nn, 1); ytemp = zeros(nn, 1);      xtemp(1:2:nn) = cs(1, k+1:k+n);      xtemp(2:2:nn) = (xtemp(1:2:nn-2) + xtemp(3:2:nn)) ./ 2;      ytemp(1:2:nn) = cs(2, k+1:k+n);      ytemp(2:2:nn) = (ytemp(1:2:nn-2) + ytemp(3:2:nn)) ./ 2;      x = [x; xtemp]; y = [y; ytemp];   % Keep these.      clist = [clist; c .* ones(2*n-1, 1)];   end   ax = axis;    xmin = ax(1); xmax = ax(2); ymin = ax(3); ymax = ax(4);   xrange = xmax - xmin; yrange = ymax - ymin;   xylist = (x .* yrange + sqrt(-1) .* y .* xrange);   view(2)   disp(' ');   disp('   Carefully select contours for labeling.')   disp('   When done, press RETURN while the Graph window is the active window.')endk = 0; n = 0; flip = 0; h = [];while (1)% Use GINPUT and select nearest point if manual.   if manual      [xx, yy, button] = ginput(1);      if isempty(button) | isequal(button,13), break, end      if xx < xmin | xx > xmax, break, end      if yy < ymin | yy > ymax, break, end      xy = xx .* yrange + sqrt(-1) .* yy .* xrange;      dist = abs(xylist - xy);      f = find(dist == min(dist));      if length(f) > 0         f = f(1); xx = x(f); yy = y(f); c = clist(f);         okay = 1;        else         okay = 0;      end   end% Select a labeling point randomly if not manual.   if ~manual      k = k + n + 1; if k > ncs, break, end      c = cs(1, k); n = cs(2, k);      if choice         f = find(abs(c-v)/max(eps+abs(v)) < .00001);         okay = length(f) > 0;      else         okay = 1;      end      if okay         r = rand;         j = fix(r.* (n - 1)) + 1;         if flip, j = n - j; end         flip = ~flip;         if n == 1    % if there is only one point           xx = cs(1, j+k); yy = cs(2, j+k);         else           x1 = cs(1, j+k); y1 = cs(2, j+k);           x2 = cs(1, j+k+1); y2 = cs(2, j+k+1);           xx = (x1 + x2) ./ 2; yy = (y1 + y2) ./ 2;  % Test was here; removed.         end      end   end% Label the point.   if okay      % Set tiny labels to zero.      if abs(c) <= 10*eps*crange, c = 0; end      % Determine format string number of digits      if cdelta > 0,         ndigits = max(3,ceil(-log10(cdelta)));      else        ndigits = 3;      end      s = num2str(c,ndigits);      hl = line('xdata',xx,'ydata',yy,'marker','+','erasemode','none');      ht = text(xx, yy, s, 'verticalalignment', 'bottom', ...             'horizontalalignment', 'left','erasemode','none', ...             'clipping','on','userdata',c,varargin{:});      if threeD,         set(hl,'zdata',c);        set(ht,'position',[xx yy c]);      end      h = [h;hl];      h = [h;ht];   endend%-------------------------------------------------------%-------------------------------------------------------function labels = getlabels(CS)%GETLABELS Get contour labelsv = []; i =1;while i < size(CS,2),   v = [v,CS(1,i)];  i = i+CS(2,i)+1;endlabels = num2str(v');%---------------------------------------------------function threeD = IsThreeD(cax)%ISTHREED  True for a contour3 plothp = findobj(cax,'type','patch');if isempty(hp), hp = findobj(gca,'type','line'); endif ~isempty(hp),  % Assume a contour3 plot if z data not empty  threeD = ~isempty(get(hp(1),'zdata'));else  threeD = 0;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -