issquare exists under Octave and returns the matrix dim if it is square

time-shift
Sébastien Villemot 2012-08-06 18:25:31 +02:00
parent 2e65a9ab96
commit db62e3d7a0
2 changed files with 9 additions and 4 deletions

View File

@ -66,8 +66,9 @@ addpath([dynareroot '/utilities/general/'])
% or some MATLAB versions, and for which we provide some replacement functions
if ~exist('OCTAVE_VERSION')
% Replacements for rows() and columns() (inexistent under MATLAB)
% Replacements for rows(), columns() and issquare() (inexistent under MATLAB)
addpath([dynareroot '/missing/rows_columns'])
addpath([dynareroot '/missing/issquare'])
% Replacement for vec() (inexistent under MATLAB)
addpath([dynareroot '/missing/vec'])
if ~user_has_matlab_license('statistics_toolbox')

View File

@ -4,7 +4,7 @@ function i = issquare(A)
%! @deftypefn {Function File} {@var{i} =} issquare (@var{A})
%! @anchor{issquare}
%! @sp 1
%! Returns 1 if @var{A} is a square matrix, 0 otherwise.
%! If @var{A} is a square matrix, returns its dimension; otherwise return 0.
%! @sp 2
%! @strong{Inputs}
%! @sp 1
@ -17,7 +17,7 @@ function i = issquare(A)
%! @sp 1
%! @table @ @var
%! @item i
%! Integer scalar (0 or 1).
%! Integer scalar.
%! @end table
%! @sp 2
%! @strong{This function is called by:}
@ -45,4 +45,8 @@ function i = issquare(A)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
d = size(A);
i = (length(d)==2) && (d(1)==d(2));
if (length(d)==2) && (d(1)==d(2))
i = d(1);
else
i = 0;
end