Code covered by the BSD License  

Highlights from
Pointers and subscript pointers

Pointers and subscript pointers

by

 

29 Jan 2011 (Updated )

Pointers implemented in Matlab

subscripthandle
% Subscript Handle Class
% This is called by the hnum class and shouldn't be used elsewhere
classdef subscripthandle < handle
  properties
    s %subscript structure
    h %handle to hnum class object
  end
  methods
    %% Constructor, destructor and disp
    function obj = subscripthandle(xhnum,sstruct)
      %created with an hnum object, and a subscript struct
      if strcmp(class(xhnum),'hnum')
        if isfield(sstruct,'subs')
          obj.s = sstruct;
          obj.h = xhnum;
        else
          error('??? Invalid subscript struct')
        end
      else
        error('??? subscripthandle must be called with an hnum class handle')
      end
    end
    function delete(obj)
      obj.h = []; %remove the handle to the hnum class, so it doesn't get deleted
    end
    function disp(obj)
      %directly calls subsref on the object handle
      % calling subsref with the obj.h structure
      % treats the obj as a structure and not an hnum.
      h=obj.h;
      s=obj.s;
      p=subsref(h,s,1);
      %p = subsref@hnum(obj.h,obj.s,1); %fails :(
      disp(p)
    end
    %% special
    % indx -- returns the index of the associated hnum object
    function x = indx(obj)
      S = obj.s;
      x = S.subs;
    end
    %parent returns the parent hnum object
    function x = parent(obj)
      x = obj.h;
    end
    %sub -- creates a new subscripthandle object 
    function x = sub(obj,varargin)
    % x = sub(obj,d1,d2,d3)
      % Returns a subscripthandle
      p = obj.s; %parent subscript to subscript
      
      newsub = subscriptsubscript(p,varargin,size(obj));
      newobj = obj.h;
      substruct.type = '()'; %create a structure
      substruct.subs = newsub;
      x = subscripthandle(newobj,substruct);
      
    end
    %% Subscripting
    function obj = subsref(obj1,s)
      % This returns values from an hnum type, but subsrefs twice.
      x = subsref(obj1.h, obj1.s, 1);
      obj = builtin('subsref',x,s);
    end
    % subasgn  x(s) = y
    function obj1 = subsasgn(obj1,s,v)
      % This is not a good way of doing it, but it handles more types of
      % subscripting. The more elegant way to do it is to modify the subscript
      % struct, but that's not as easy as it sounds.
      x = subsref(obj1.h, obj1.s, 1); %this returns the major subscript
      y = builtin('subsasgn',x,s,v);  %create a replacement for the whole thing
      z = subsasgn(obj1.h,obj1.s,y);%#ok<*NASGU> %moves y to an hnum object. Returns a handle
      %returns obj1, which shows the update
    end
    
    % subsindex
    % this is called with A(x) where A is some matrix, and x points to an hnum
    function indx = subsindex(obj)
      indx = subsref(obj.h, obj.s, 1)-1;
    end
    
    %end -- in the context of x(1:end)
    function ind = end(obj,k,n)
      x = subsref(obj.h, obj.s, 1);
      szd = size(x);
      if k < n
        ind = szd(k);
      else
        ind = prod(szd(k:end));
      end
    end
    %% size,numel,length
    function [x,y,z] = size(obj)
      %Room for improvement here. Currently it copies the array to find the size...
      a = subsref(obj.h, obj.s, 1);
      if nargout == 0
        disp(size(a))
      elseif nargout == 1
        x = size(a);
      elseif nargout == 2
        [x y] = size(a);
      elseif nargout == 3
        [x y z] = size(a);
      end
    end
    function x = numel(obj)
      a = subsref(obj.h, obj.s, 1);
      x = numel(a);
    end
    function x = length(obj)
      a = subsref(obj.h, obj.s, 1);
      x = length(a);
    end
    %% Auto-Generated overloading methods
    % used buildoverloadsubscript
    
    % abs(obj)
    function x = abs(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('abs',y);
    end
    % accumarray(obj1,obj2)
    function x = accumarray(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('accumarray',y,obj2.val);
      else
        x = builtin('accumarray',y,obj2);
      end
    end
    % acos(obj)
    function x = acos(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acos',y);
    end
    % acosd(obj)
    function x = acosd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acosd',y);
    end
    % acosh(obj)
    function x = acosh(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acosh',y);
    end
    % acot(obj)
    function x = acot(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acot',y);
    end
    % acotd(obj)
    function x = acotd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acotd',y);
    end
    % acoth(obj)
    function x = acoth(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acoth',y);
    end
    % acsc(obj)
    function x = acsc(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acsc',y);
    end
    % acscd(obj)
    function x = acscd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acscd',y);
    end
    % acsch(obj)
    function x = acsch(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('acsch',y);
    end
    % all(obj)
    function x = all(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('all',y);
    end
    % amd(obj)
    function x = amd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('amd',y);
    end
    % and(obj1,obj2)
    function x = and(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('and',y,obj2.val);
      else
        x = builtin('and',y,obj2);
      end
    end
    % any(obj)
    function x = any(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('any',y);
    end
    % asec(obj)
    function x = asec(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('asec',y);
    end
    % asecd(obj)
    function x = asecd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('asecd',y);
    end
    % asech(obj)
    function x = asech(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('asech',y);
    end
    % asin(obj)
    function x = asin(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('asin',y);
    end
    % asind(obj)
    function x = asind(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('asind',y);
    end
    % asinh(obj)
    function x = asinh(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('asinh',y);
    end
    % atan(obj)
    function x = atan(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('atan',y);
    end
    % atan2(obj1,obj2)
    function x = atan2(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('atan2',y,obj2.val);
      else
        x = builtin('atan2',y,obj2);
      end
    end
    % atand(obj)
    function x = atand(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('atand',y);
    end
    % atanh(obj)
    function x = atanh(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('atanh',y);
    end
    % balance(obj)
    function x = balance(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('balance',y);
    end
    % bitand(obj1,obj2)
    function x = bitand(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitand',y,obj2.val);
      else
        x = builtin('bitand',y,obj2);
      end
    end
    % bitcmp(obj1,obj2)
    function x = bitcmp(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitcmp',y,obj2.val);
      else
        x = builtin('bitcmp',y,obj2);
      end
    end
    % bitget(obj1,obj2)
    function x = bitget(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitget',y,obj2.val);
      else
        x = builtin('bitget',y,obj2);
      end
    end
    % bitor(obj1,obj2)
    function x = bitor(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitor',y,obj2.val);
      else
        x = builtin('bitor',y,obj2);
      end
    end
    % bitset(obj1,obj2)
    function x = bitset(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitset',y,obj2.val);
      else
        x = builtin('bitset',y,obj2);
      end
    end
    % bitshift(obj1,obj2)
    function x = bitshift(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitshift',y,obj2.val);
      else
        x = builtin('bitshift',y,obj2);
      end
    end
    % bitxor(obj1,obj2)
    function x = bitxor(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('bitxor',y,obj2.val);
      else
        x = builtin('bitxor',y,obj2);
      end
    end
    % ceil(obj)
    function x = ceil(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('ceil',y);
    end
    % chol(obj)
    function x = chol(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('chol',y);
    end
    % cholupdate(obj1,obj2)
    function x = cholupdate(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('cholupdate',y,obj2.val);
      else
        x = builtin('cholupdate',y,obj2);
      end
    end
    % colon(obj1,obj2)
    function x = colon(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('colon',y,obj2.val);
      else
        x = builtin('colon',y,obj2);
      end
    end
    % conj(obj)
    function x = conj(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('conj',y);
    end
    % conv2(obj1,obj2)
    function x = conv2(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('conv2',y,obj2.val);
      else
        x = builtin('conv2',y,obj2);
      end
    end
    % cos(obj)
    function x = cos(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cos',y);
    end
    % cosd(obj)
    function x = cosd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cosd',y);
    end
    % cosh(obj)
    function x = cosh(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cosh',y);
    end
    % cot(obj)
    function x = cot(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cot',y);
    end
    % cotd(obj)
    function x = cotd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cotd',y);
    end
    % coth(obj)
    function x = coth(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('coth',y);
    end
    % csc(obj)
    function x = csc(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('csc',y);
    end
    % cscd(obj)
    function x = cscd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cscd',y);
    end
    % csch(obj)
    function x = csch(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('csch',y);
    end
    % ctranspose(obj)
    function x = ctranspose(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('ctranspose',y);
    end
    % cumprod(obj)
    function x = cumprod(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cumprod',y);
    end
    % cumsum(obj)
    function x = cumsum(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('cumsum',y);
    end
    % det(obj)
    function x = det(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('det',y);
    end
    % diag(obj)
    function x = diag(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('diag',y);
    end
    % diff(obj)
    function x = diff(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('diff',y);
    end
    % dmperm(obj)
    function x = dmperm(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('dmperm',y);
    end
    % eig(obj)
    function x = eig(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('eig',y);
    end
    % eps(obj)
    function x = eps(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('eps',y);
    end
    % erf(obj)
    function x = erf(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('erf',y);
    end
    % erfc(obj)
    function x = erfc(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('erfc',y);
    end
    % erfcinv(obj)
    function x = erfcinv(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('erfcinv',y);
    end
    % erfcx(obj)
    function x = erfcx(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('erfcx',y);
    end
    % erfinv(obj)
    function x = erfinv(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('erfinv',y);
    end
    % exp(obj)
    function x = exp(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('exp',y);
    end
    % fft(obj)
    function x = fft(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('fft',y);
    end
    % fftn(obj)
    function x = fftn(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('fftn',y);
    end
    % find(obj)
    function x = find(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('find',y);
    end
    % fix(obj)
    function x = fix(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('fix',y);
    end
    % floor(obj)
    function x = floor(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('floor',y);
    end
    % full(obj)
    function x = full(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('full',y);
    end
    % gamma(obj)
    function x = gamma(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('gamma',y);
    end
    % gammainc(obj1,obj2)
    function x = gammainc(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('gammainc',y,obj2.val);
      else
        x = builtin('gammainc',y,obj2);
      end
    end
    % gammaincinv(obj1,obj2)
    function x = gammaincinv(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('gammaincinv',y,obj2.val);
      else
        x = builtin('gammaincinv',y,obj2);
      end
    end
    % gammaln(obj)
    function x = gammaln(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('gammaln',y);
    end
    % hess(obj)
    function x = hess(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('hess',y);
    end
    % hypot(obj1,obj2)
    function x = hypot(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('hypot',y,obj2.val);
      else
        x = builtin('hypot',y,obj2);
      end
    end
    % ifft(obj)
    function x = ifft(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('ifft',y);
    end
    % ifftn(obj)
    function x = ifftn(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('ifftn',y);
    end
    % imag(obj)
    function x = imag(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('imag',y);
    end
    % inv(obj)
    function x = inv(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('inv',y);
    end
    % isfinite(obj)
    function x = isfinite(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('isfinite',y);
    end
    % isinf(obj)
    function x = isinf(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('isinf',y);
    end
    % isnan(obj)
    function x = isnan(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('isnan',y);
    end
    % issorted(obj)
    function x = issorted(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('issorted',y);
    end
    % jit_breakpoint(obj)
    function x = jit_breakpoint(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('jit_breakpoint',y);
    end
    % ldivide(obj1,obj2)
    function x = ldivide(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('ldivide',y,obj2.val);
      else
        x = builtin('ldivide',y,obj2);
      end
    end
    % ldl(obj)
    function x = ldl(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('ldl',y);
    end
    % linsolve(obj1,obj2)
    function x = linsolve(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('linsolve',y,obj2.val);
      else
        x = builtin('linsolve',y,obj2);
      end
    end
    % log(obj)
    function x = log(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('log',y);
    end
    % log2(obj)
    function x = log2(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('log2',y);
    end
    % lu(obj)
    function x = lu(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('lu',y);
    end
    % max(obj)
    function x = max(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('max',y);
    end
    % min(obj)
    function x = min(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('min',y);
    end
    % minus(obj1,obj2)
    function x = minus(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('minus',y,obj2.val);
      else
        x = builtin('minus',y,obj2);
      end
    end
    % mldivide(obj1,obj2)
    function x = mldivide(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('mldivide',y,obj2.val);
      else
        x = builtin('mldivide',y,obj2);
      end
    end
    % mod(obj1,obj2)
    function x = mod(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('mod',y,obj2.val);
      else
        x = builtin('mod',y,obj2);
      end
    end
    % mpower(obj1,obj2)
    function x = mpower(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('mpower',y,obj2.val);
      else
        x = builtin('mpower',y,obj2);
      end
    end
    % mrdivide(obj1,obj2)
    function x = mrdivide(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('mrdivide',y,obj2.val);
      else
        x = builtin('mrdivide',y,obj2);
      end
    end
    % mtimes(obj1,obj2)
    function x = mtimes(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('mtimes',y,obj2.val);
      else
        x = builtin('mtimes',y,obj2);
      end
    end
    % nnz(obj)
    function x = nnz(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('nnz',y);
    end
    % nonzeros(obj)
    function x = nonzeros(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('nonzeros',y);
    end
    % norm(obj)
    function x = norm(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('norm',y);
    end
    % not(obj)
    function x = not(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('not',y);
    end
    % nzmax(obj)
    function x = nzmax(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('nzmax',y);
    end
    % or(obj1,obj2)
    function x = or(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('or',y,obj2.val);
      else
        x = builtin('or',y,obj2);
      end
    end
    % ordeig(obj)
    function x = ordeig(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('ordeig',y);
    end
    % plus(obj1,obj2)
    function x = plus(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('plus',y,obj2.val);
      else
        x = builtin('plus',y,obj2);
      end
    end
    % pow2(obj)
    function x = pow2(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('pow2',y);
    end
    % power(obj1,obj2)
    function x = power(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('power',y,obj2.val);
      else
        x = builtin('power',y,obj2);
      end
    end
    % prod(obj)
    function x = prod(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('prod',y);
    end
    % qr(obj)
    function x = qr(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('qr',y);
    end
    % qz(obj1,obj2)
    function x = qz(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('qz',y,obj2.val);
      else
        x = builtin('qz',y,obj2);
      end
    end
    % rcond(obj)
    function x = rcond(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('rcond',y);
    end
    % rdivide(obj1,obj2)
    function x = rdivide(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('rdivide',y,obj2.val);
      else
        x = builtin('rdivide',y,obj2);
      end
    end
    % real(obj)
    function x = real(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('real',y);
    end
    % reallog(obj)
    function x = reallog(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('reallog',y);
    end
    % realpow(obj1,obj2)
    function x = realpow(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('realpow',y,obj2.val);
      else
        x = builtin('realpow',y,obj2);
      end
    end
    % realsqrt(obj)
    function x = realsqrt(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('realsqrt',y);
    end
    % rem(obj1,obj2)
    function x = rem(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('rem',y,obj2.val);
      else
        x = builtin('rem',y,obj2);
      end
    end
    % round(obj)
    function x = round(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('round',y);
    end
    % schur(obj)
    function x = schur(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('schur',y);
    end
    % sec(obj)
    function x = sec(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sec',y);
    end
    % secd(obj)
    function x = secd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('secd',y);
    end
    % sech(obj)
    function x = sech(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sech',y);
    end
    % sign(obj)
    function x = sign(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sign',y);
    end
    % sin(obj)
    function x = sin(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sin',y);
    end
    % sind(obj)
    function x = sind(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sind',y);
    end
    % sinh(obj)
    function x = sinh(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sinh',y);
    end
    % sort(obj)
    function x = sort(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sort',y);
    end
    % sortrowsc(obj1,obj2)
    function x = sortrowsc(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('sortrowsc',y,obj2.val);
      else
        x = builtin('sortrowsc',y,obj2);
      end
    end
    % sparse(obj)
    function x = sparse(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sparse',y);
    end
    % speye(obj)
    function x = speye(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('speye',y);
    end
    % sqrt(obj)
    function x = sqrt(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sqrt',y);
    end
    % sum(obj)
    function x = sum(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('sum',y);
    end
    % superiorfloat(obj)
    function x = superiorfloat(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('superiorfloat',y);
    end
    % svd(obj)
    function x = svd(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('svd',y);
    end
    % symrcm(obj)
    function x = symrcm(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('symrcm',y);
    end
    % tan(obj)
    function x = tan(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('tan',y);
    end
    % tand(obj)
    function x = tand(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('tand',y);
    end
    % tanh(obj)
    function x = tanh(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('tanh',y);
    end
    % times(obj1,obj2)
    function x = times(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('times',y,obj2.val);
      else
        x = builtin('times',y,obj2);
      end
    end
    % transpose(obj)
    function x = transpose(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('transpose',y);
    end
    % tril(obj)
    function x = tril(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('tril',y);
    end
    % triu(obj)
    function x = triu(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('triu',y);
    end
    % uminus(obj)
    function x = uminus(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('uminus',y);
    end
    % uplus(obj)
    function x = uplus(obj)
      y = subsref(obj.h, obj.s, 1);
      x = builtin('uplus',y);
    end
    % xor(obj1,obj2)
    function x = xor(obj1,obj2)
      y = subsref(obj1.h, obj1.s, 1);
      if strcmp(class(obj2),'hnum')
        x = builtin('xor',y,obj2.val);
      else
        x = builtin('xor',y,obj2);
      end
    end
    % betainc  Is Unused
    % betaincinv  Is Unused
    % bsxfun  Is Unused
    % cholinc  Is Unused
    % display  Is Unused
    % exist  Is Unused
    % fftw  Is Unused
    % filter  Is Unused
    % ilu  Is Unused
    % ltitr  Is Unused
    % luinc  Is Unused
    % mimofr  Is Unused
    % ordqz  Is Unused
    % ordschur  Is Unused
    % permute  Is Unused
    % qrupdate  Is Unused
    % reshape  Is Unused
    % sparsfun  Is Unused
    % trmginput  Is Unused
    
    
  end
end

%% SUBSCRIPTSUBSCRIPT  Subscripts a subscript
% x = subscriptsubscript(a,b,s)
% returns a subscript cell
% a is the parent subscript, and b is the child subscript
% s is a size vector
function x = subscriptsubscript(a,b,s)
  if isstruct(a) %cells pass through
    a=a.subs; %throw away the type, which will always be '()'
  end
  x{numel(b)} = [];
  % convert char shortcuts to vectors
  for i = 1:numel(a)
    if ischar(a{i}) % either : or end
      if strcmp(a{i},':')
        a{i} = [1:s(i)];
      elseif strcmp(a{i},'end')
        a{i} = s(i);
      else
        error('??? Invalid subscript cell')
      end
    elseif islogical(a{i})
      error('??? logical subscripting of subscripts is not available')
    elseif isnumeric(a{i})
      %Don't check these. Let the builtin subscripting create errors
    else
      error('??? Invalid subscript cell')
    end
  end
  for i = 1:numel(b)
    if ischar(b{i}) % either : or end
      if strcmp(b{i},':')
        x{i} = a{i}; %select all of this dimension
      elseif strcmp(b{i},'end')
        c = a{i};  %cant do a{i}(end)
        x{i} = c(end);
      else   %for the cases of '1:end' , '2:end-1' , etc
        try
          c = a{i};
          d = b{i};
          eval(['x{i} = c(',d,');']);
        catch
          error('??? Invalid subscript cell')
        end
      end
    elseif islogical(b{i})
      error('??? logical subscripting of subscripts is not available')
    elseif isnumeric(b{i})
      c = a{i};
      d = b{i};
      x{i} = c(d);
    else
      error('??? Invalid subscript cell ')
    end
  end
end

Contact us