View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
UNINIT - Create an uninitialized variable (like ZEROS but faster)

5.0 | 2 ratings Rate this file 9 Downloads (last 30 days) File Size: 7.24 KB File ID: #31362 Version: 1.0
image thumbnail

UNINIT - Create an uninitialized variable (like ZEROS but faster)


James Tursa (view profile)


UNINIT is similar to ZEROS, except UNINIT returns uninitialized values instead of zero values.

| Watch this File

File Information

UNINIT is very similar to the ZEROS function, except that UNINIT returns an uninitialized array instead of a zero-filled array. Thus, UNINIT is faster than the ZEROS function for large size arrays. Since the return variable is uninitialized, the user must take care to assign values to the elements before using them. UNINIT is useful for preallocation of an array where you know the elements will be assigned values before using them.

Syntax (nearly identical to the ZEROS function)
  B = uninit
  B = uninit(n)
  B = uninit(m,n)
  B = uninit([m n])
  B = uninit(m,n,p,...)
  B = uninit([m n p ...])
  B = uninit(size(A))
  B = uninit(m, n,...,classname)
  B = uninit([m,n,...],classname)
  B = uninit(m, n,...,complexity)
  B = uninit([m,n,...],complexity)
  B = uninit(m, n,...,classname,complexity)
  B = uninit([m,n,...],classname,complexity)
  B = uninit
      Returns a 1-by-1 scalar uninitialized value.

  B = uninit(n)
      Returns an n-by-n matrix of uninitialized values. An error message
      appears if n is not a scalar.

  B = uninit(m,n) or B = uninit([m n])
      Returns an m-by-n matrix of uninitialized values.

  B = uninit(m,n,p,...) or B = uninit([m n p ...])
      Returns an m-by-n-by-p-by-... array of uninitialized values. The
      size inputs m, n, p, ... should be nonnegative integers. Negative
      integers are treated as 0.

  B = uninit(size(A))
      Returns an array the same size as A consisting of all uninitialized

  If any of the numeric size inputs are empty, they are taken to be 0.

  The optional classname argument can be used with any of the above.
  classname is a string specifying the data type of the output.
  classname can have the following values:
          'double', 'single', 'int8', 'uint8', 'int16', 'uint16',
          'int32', 'uint32', 'int64', 'uint64', 'logical', or 'char'.
          (Note: 'logical' and 'char' are not allowed in the ZEROS function)
  The default classname is 'double'.

  The optional complexity argument can be used with any of the above.
  complexity can be 'real' or 'complex', except that 'logical' and 'char'
  outputs cannot be complex. (this option not allowed in the ZEROS function)
  The default complexity is 'real'.

UNINIT is typically self building. That is, the first time you call UNINIT, the uninit.m file recognizes that the mex routine needs to be compiled and then the compilation will happen automatically. UNINIT uses the undocumented MATLAB API function mxCreateUninitNumericMatrix. It has been tested in PC WinXP versions R2006b through R2011a, but may not work in future versions or non-PC versions of MATLAB.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements Requires a C compiler, such as the built-in lcc compiler. UNINIT is a self-building mex file ... you don't have to know anything about C or mex to use it.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
28 Sep 2016 Dan Po

Dan Po (view profile)

looks like a really good idea

Comment only
11 Dec 2014 Sagar

Sagar (view profile)

I got the following error, any idea?


No supported SDK or compiler was found on this computer.
For a list of supported compilers, see

Error using uninit (line 148)
Unable to compile uninit ... Contact author.

Comment only
18 May 2012 nedjma ALI

14 Feb 2012 Markus Reiband

Absolutly perfect!!!

We were able to greatly improve performance of our scripts because we work with very large matrices. This way of fast allocation memory should become a part of the standard Matlab!

10 May 2011 Jonathan Sullivan

This is much faster at allocating memory that zeros, or false. If you do any sort of operation on it, it becomes slower than zeros / false. This is best used for quick allocation of memory when you are about to overwrite the values anyways.

The self-compiler makes it really easy to use. Your just simply hit run, and it will compile itself for you.

Great work!

Comment only

Contact us