home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / GRAPHICS.DI$ / COLSTYLE.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.5 KB  |  64 lines

  1. function [style,color] = colstyle(A)
  2. %COLSTYLE  Parse color and style from string for graphics.
  3.  
  4. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  5.  
  6. if nargin < 1
  7.     error('Requires one input argument.');
  8. end
  9. a = A;
  10. if ~isstr(a)
  11.     error('Argument must be a string.');
  12. end
  13. if length(a) > 4
  14.     error('Invalid color and style string.')
  15. end
  16. valid_colors = 'ymrgbwkc'; % and don't forget c followed by an integer
  17. valid_styles = '-.:xo*+'; % don't forget -- and -.
  18.  
  19. color = [];
  20. for i = 1:length(a)
  21.     k = find(a(i) == valid_colors);
  22.     if ~isempty(k)    % found a color - if they give extra colors, too bad
  23.         color = a(i);
  24.         if (color == 'c') % see if there's an integer after it
  25.             if length(a) > i  % not end of string
  26.                 next = abs(a(i+1));
  27.                 if next > 47 & next < 58 % a digit
  28.                     color = [color a(i+1)];
  29.                     if length(a) > i+1 % another character
  30.                         next1 = abs(a(i+2));
  31.                         if next1 > 47 & next1 < 58 % a digit
  32.                             color = [color a(i+2)];
  33.                             a(i+2) = [];
  34.                         end
  35.                     end
  36.                     a(i+1) = [];
  37.                 end
  38.             end
  39.         end
  40.         a(i) = [];
  41.         break;
  42.     end
  43. end
  44.  
  45. style = [];
  46. for i = 1:length(a)
  47.     k = find(a(i) == valid_styles);
  48.     if ~isempty(k) % found a style
  49.         style = a(i);
  50.         if (style == '-') % see if this is followed by - or .
  51.             if length(a) > i % not end of string
  52.                 next = a(i+1);
  53.                 if next == '-' | next == '.'
  54.                     style = [style next];
  55.                 end
  56.                 break;
  57.             end
  58.         end
  59.     end
  60. end
  61. if length(style)+length(color) ~= length(A)
  62.     error('Invalid color and style string.')
  63. end
  64.