time | calls | line |
---|
| | 1 | function [msg,x,y,xi] = xychk(varargin)
|
| | 2 | %XYCHK Check arguments to 1-D and 2-D data routines.
|
| | 3 | % [MSG,X,Y] = XYCHK(Y), or
|
| | 4 | % [MSG,X,Y] = XYCHK(X,Y), or
|
| | 5 | % [MSG,X,Y,XI] = XYCHK(X,Y,XI) checks the input arguments and returns
|
| | 6 | % either an error structure in MSG or valid X,Y (and XI) data. MSG is
|
| | 7 | % empty when there is no error. X must be a vector and Y must have
|
| | 8 | % length(x) rows (or be a vector itself).
|
| | 9 | %
|
| | 10 | % [MSG,X,Y] = XYCHK(X,Y,'plot') allows X and Y to be matrices by
|
| | 11 | % treating them the same as PLOT does.
|
| | 12 |
|
| | 13 | % Copyright 1984-2011 The MathWorks, Inc.
|
| | 14 |
|
| 37 | 15 | narginchk(1,3);
|
| | 16 |
|
| 37 | 17 | nin = nargin; x = []; y = []; xi = [];
|
| | 18 |
|
| 37 | 19 | msg.message = '';
|
| 37 | 20 | msg.identifier = '';
|
| 37 | 21 | msg = msg(zeros(0,1));
|
| | 22 |
|
| 37 | 23 | if nin > 1 && ischar(varargin{end}),
|
| 37 | 24 | plot_flag = 1;
|
| 37 | 25 | nin = nin - 1;
|
| | 26 | else
|
| | 27 | plot_flag = 0;
|
| | 28 | end
|
| | 29 |
|
| 37 | 30 | if nin==1, % xychk(y)
|
| | 31 | if ischar(varargin{1}),
|
| | 32 | msg(1).identifier = 'MATLAB:xychk:nonNumericInput';
|
| | 33 | msg(1).message = getString(message(msg(1).identifier));
|
| | 34 | return
|
| | 35 | end
|
| | 36 | y = varargin{1};
|
| | 37 | if ndims(y)>2,
|
| | 38 | msg(1).identifier = 'MATLAB:xychk:non2DInput';
|
| | 39 | msg(1).message = getString(message(msg(1).identifier));
|
| | 40 | return,
|
| | 41 | end
|
| | 42 | if ~isreal(y), % Deal with complex data case.
|
| | 43 | if min(size(y))>1 && plot_flag,
|
| | 44 | msg(1).identifier = 'MATLAB:xychk:nonComplexVectorInput';
|
| | 45 | msg(1).message = getString(message(msg(1).identifier));
|
| | 46 | end
|
| | 47 | x = real(y); y = imag(y);
|
| | 48 | return
|
| | 49 | end
|
| | 50 | if plot_flag==1 && min(size(y))==1, y = y(:); end
|
| | 51 | if min(size(y))==1,
|
| | 52 | x = reshape(1:length(y),size(y));
|
| | 53 | else
|
| | 54 | x = (1:size(y,1))';
|
| | 55 | end
|
| | 56 | if plot_flag==1 && min(size(y))>1,
|
| | 57 | x = x(:,ones(1,size(y,2)));
|
| | 58 | end
|
| | 59 |
|
| 37 | 60 | elseif nin>=2, % xychk(x,y) or xychk(x,y,xi) or xychk(x,y,flag)
|
| 37 | 61 | x = varargin{1};
|
| 37 | 62 | y = varargin{2};
|
| 37 | 63 | if ndims(x)>2 || ndims(y)>2
|
| | 64 | msg(1).identifier = 'MATLAB:xychk:non2DInput';
|
| | 65 | msg(1).message = getString(message(msg(1).identifier));
|
| | 66 | return
|
| | 67 | end
|
| 37 | 68 | if nin==3, xi = varargin{3}; end
|
| 37 | 69 | if ~plot_flag % xychk(x,y,...)
|
| | 70 | if min(size(x))>1,
|
| | 71 | msg(1).identifier = 'MATLAB:xychk:XNotAVector';
|
| | 72 | msg(1).message = getString(message(msg(1).identifier));
|
| | 73 | return,
|
| | 74 | end
|
| | 75 | if min(size(x))==1, x = x(:); end
|
| | 76 | if min(size(y))>1, % y is a matrix
|
| | 77 | if length(x)~=size(y,1),
|
| | 78 | msg(1).identifier = 'MATLAB:xychk:lengthXDoesNotMatchNumRowsY';
|
| | 79 | msg(1).message = getString(message(msg(1).identifier));
|
| | 80 | return
|
| | 81 | end
|
| | 82 | else % y is a vector
|
| | 83 | if length(x) ~= length(y),
|
| | 84 | msg(1).identifier = 'MATLAB:xychk:XAndYLengthMismatch';
|
| | 85 | msg(1).message = getString(message(msg(1).identifier));
|
| | 86 | return
|
| | 87 | end
|
| | 88 | % Make sure x has the same orientation as y.
|
| | 89 | x = reshape(x,size(y));
|
| | 90 | end
|
| 37 | 91 | else % xychk(x,y,'plot')
|
| 37 | 92 | isvectorY = min(size(y)) == 1; % false when y empty
|
| 37 | 93 | if min(size(x))==1, x = x(:); end
|
| 37 | 94 | if isvectorY, y = y(:); end
|
| | 95 | % Copy x as columns.
|
| 37 | 96 | if size(x,2)==1, x = x(:,ones(1,size(y,2))); end
|
| 37 | 97 | if ~isvectorY && (size(x,1) ~= size(y,1))
|
| | 98 | msg(1).identifier = 'MATLAB:xychk:lengthXDoesNotMatchNumRowsY';
|
| | 99 | msg(1).message = getString(message(msg(1).identifier));
|
| | 100 | return
|
| 37 | 101 | elseif isvectorY && length(x) ~= length(y)
|
| | 102 | msg(1).identifier = 'MATLAB:xychk:XAndYLengthMismatch';
|
| | 103 | msg(1).message = getString(message(msg(1).identifier));
|
| | 104 | return
|
| | 105 | end
|
| 37 | 106 | if ~isequal(size(x),size(y)),
|
| | 107 | msg(1).identifier = 'MATLAB:xychk:XAndYSizeMismatch';
|
| | 108 | msg(1).message = getString(message(msg(1).identifier));
|
| | 109 | return
|
| | 110 | end
|
| 37 | 111 | end
|
| 37 | 112 | end
|
Other subfunctions in this file are not included in this listing.