tag:www.mathworks.com,2005:/matlabcentral/fileexchange/feedMATLAB Central File Exchangeicon.pnglogo.pngMATLAB Central - File Exchange - category:"Object-Oriented Programming"User-contributed code library2014-11-27T23:46:31-05:00831100tag:www.mathworks.com,2005:FileInfo/179352007-12-08T19:54:14Z2014-11-21T13:55:16ZUIINSPECT - display methods, properties & callbacks of an objectInspect an object handle (Java/COM/HG); display its methods/properties/callbacks in a unified window<p>Syntax:
<br />hFig = uiinspect(obj)
<br />
<br />Description:
<br />UIINSPECT inspects an object handle (e.g., Java, COM, Handle Graphics, Matlab class, Dot-Net etc.) and displays the inspection results in a unified Matlab window. UIINSPECT displays a unified window with all relevant object methods (as can be displayed via Matlab's methodsview function), properties (as can be displayed via Matlab's inspect function), static fields, and callbacks. UIINSPECT also displays properties and fields that are not normally displayed with Matlab's inspect function. Property meta-data such as type, accessibility, visibility and default value are also displayed.
<br />Unlike Matlab's inspect function, multiple UIINSPECT windows can be opened simultaneously.
<br />
<br />Object properties and callbacks may be modified interactively within the UIINSPECT window.
<br />
<br />hFig = UIINSPECT returns a handle to the created figure window. UIINSPECT opens a regular Matlab figure window which may be accessed via hFig (unlike Matlab's methodsview function which opens a Java frame that is not easily accessible from Matlab).
<br />
<br />Examples:
<br />hFig = uiinspect(0); % Matlab root (desktop) handle
<br />hFig = uiinspect(handle(0));
<br />hFig = uiinspect(gcf); % Figure handle
<br />hFig = uiinspect(handle(gcf));
<br />uiinspect(get(gcf,'JavaFrame'));
<br />uiinspect(classhandle(handle(gcf))); % UDD handle
<br />uiinspect(findprop(handle(gcf),'MenuBar')); % Meta-data handle
<br />uiinspect('java.lang.String'); % Java class name
<br />uiinspect(java.lang.String('yes')); % Java class object reference
<br />uiinspect(actxserver('Excel.Application')); % COM/ActiveX object
<br />uiinspect(Employee) % Matlab class object
<br />uiinspect(?handle) % Matlab metaclass object
<br />uiinspect('meta.class') % Matlab class name
<br />uiinspect(System.Diagnostics.Process.GetCurrentProcess) % Dot-Net object
<br />Warning:
<br />This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7.1 and later releases, but use at your own risk!</p>
<p>Technical explanation and details:
<br /><a href="http://undocumentedmatlab.com/blog/uiinspect">http://undocumentedmatlab.com/blog/uiinspect</a></p>
<p>Bugs and suggestions:
<br />Please send to Yair Altman (altmany at gmail dot com)</p>Yair Altmanhttp://www.mathworks.com/matlabcentral/fileexchange/authors/27420MATLAB 7.4 (R2007a)14317falsetag:www.mathworks.com,2005:FileInfo/320252011-07-01T11:54:15Z2014-11-09T12:21:04ZRead TIFF / TIF stacks efficiently, with lazy loadingRead a TIFF stack as a memory-mapped tensor. Handles a large range of internal TIFF formats.<p>See also <a href="http://dylan-muir.com/articles/tiffstack/">http://dylan-muir.com/articles/tiffstack/</a>
<br />Usage: tsStack = TIFFStack(strFilename <, bInvert>)
<br />A TIFFStack object behaves like a read-only memory mapped TIF file. The entire image stack is treated as a matlab tensor. Each frame of the file must have the same dimensions. Reading the image data is optimised to the extent possible; the header information is only read once.
<br />
<br />This class attempts to use the version of tifflib built-in to recent versions of Matlab, if available. Otherwise this class uses a modified version of tiffread [1, 2] to read data. Code is included (but disabled) to use the matlab imread function, but imread returns invalid data for some TIFF formats.
<br />permute, ipermute and transpose are now transparantly supported. Note that to read a pixel, the entire frame containing that pixel is read. So reading a Z-slice of the stack will read in the entire stack.
<br />Construction:
<br />>> tsStack = TIFFStack('test.tiff'); % Construct a TIFF stack associated with a file
<br />>> tsStack = TIFFStack('test.tiff', true); % Indicate that the image data should be inverted
<br />tsStack =
<br /> TIFFStack handle
<br /> Properties:
<br /> bInvert: 0
<br /> strFilename: [1x9 char]
<br /> sImageInfo: [5x1 struct]
<br /> strDataClass: 'uint16'</p>
<p>Usage:
<br />>> tsStack(:, :, 3); % Retrieve the 3rd frame of the stack, all planes
<br />>> tsStack(:, :, 1, 3); % Retrieve the 3rd plane of the 1st frame
<br />>> size(tsStack) % Find the size of the stack (rows, cols, frames, planes per pixel)</p>
<p>ans =
<br /> 128 128 5 1</p>
<p>>> tsStack(4); % Linear indexing is supported
<br />>> tsStack.bInvert = true; % Turn on data inversion</p>
<p>References:
<br />[1] Francois Nedelec, Thomas Surrey and A.C. Maggs. Physical Review Letters 86: 3192-3195; 2001. DOI: 10.1103/PhysRevLett.86.3192
<br />[2] <a href="http://www.cytosim.org/misc/">http://www.cytosim.org/misc/</a>
<br /> </p>Dylan Muirhttp://www.mathworks.com/matlabcentral/fileexchange/authors/119513MATLAB 7.11 (R2010b)MATLABfalsetag:www.mathworks.com,2005:FileInfo/296942010-12-13T13:46:06Z2014-11-05T11:02:57ZMappedTensor class - memory-mapped filesA better, transparent memmapfile, with complex number support.<p>See also <a href="http://dylan-muir.com/articles/mapped_tensor/">http://dylan-muir.com/articles/mapped_tensor/</a>
<br />This class transparently maps large tensors of arbitrary dimensions to temporary files on disk. Referencing is identical to a standard matlab tensor, so a MappedTensor can be passed into functions without requiring that the function be written specifically to use MappedTensors. This is opposed to memmapfile objects, which cannot be used in such a way. Being able to used MappedTensors as arguments requires that the tensor is indexed inside the function (as opposed to using the object with no indices). This implies that a function using a MappedTensor must not be fully vectorised, but must operate on the mapped tensor in segments inside a for loop.
<br />MappedTensor also offers support for basic operations such as permute and sum, without requiring space for the tensor to be allocated in memory. memmapfile sometimes runs out of virtual addressing space, even if the data is stored only on disk. MappedTensor does not suffer from this problem.</p>
<p>Functions that work on every element of a tensor, with an output the same size as the input tensor, can be applied to a MappedTensor without requiring the entire tensor to be allocated in memory. This is done with the convenience function "SliceFunction".</p>
<p>An existing binary file can also be mapped, similarly to memmapfile. However, memmapfile offers more flexibility in terms of file format. MappedTensors transparently support complex numbers, which is an advantage over memmapfile.</p>
<p>Example:
<br />mtVar = MappedTensor(500, 500, 1000, 'Class', 'single');
<br />% A new tensor is created, 500x500x1000 of class 'single'.
<br />% A temporary file is generated on disk to contain the data for this tensor.</p>
<p>for (i = 1:1000)
<br /> mtVar(:, :, i) = rand(500, 500);
<br /> mtVar(:, :, i) = abs(fft(mtVar(:, :, i)));
<br />end</p>
<p>mtVar = mtVar';</p>
<p>mtVar(3874)</p>
<p>mtVar(:, 1, 1)</p>
<p>mfSum = sum(mtVar, 3);
<br />% The sum is performed without allocating space for mtVar in
<br />% memory.</p>
<p>mtVar2 = SliceFunction(mtVar, @(m)(fft2(m), 3);
<br />% 'fft2' will be applied to each Z-slice of mtVar
<br />% in turn, with the result returned in the newly-created
<br />% MappedTensor mtVar2.</p>
<p>clear mtVar mtVar2
<br />% The temporary files are removed</p>
<p>mtVar = MappedTensor('DataDump.bin', 500, 500, 1000);
<br />% The file 'DataDump.bin' is mapped to mtVar.</p>
<p>SliceFunction(mtVar, @()(randn(500, 500)), 3);
<br />% "Slice assignment" is supported, by using "generator" functions that accept no arguments. The assignment occurs while only allocating space for a single tensor slice in memory.</p>
<p>mtVar = -mtVar;
<br />mtVar = 5 + mtVar;
<br />mtVar = 5 - mtVar;
<br />mtVar = 12 .* mtVar;
<br />mtVar = mtVar / 5;
<br />% Unary and binary mathematical operations are supported, as long as they are performed with a scalar. Multiplication, division and negation take O(1) time; addition and subtraction take O(N) time.</p>Dylan Muirhttp://www.mathworks.com/matlabcentral/fileexchange/authors/119513MATLAB 7.8 (R2009a)MATLABfalsetag:www.mathworks.com,2005:FileInfo/479252014-09-24T20:33:56Z2014-09-24T22:01:53ZMATLAB Table Fundamentals.pdfTutorial on the new table class<p>This is a tutorial on tables, which were introduced in R2013b.
<br />A table is a MATLABÂ® container for storing column-oriented variables that have the same number of rows. Unlike numerical or character arrays, the columns can have different data types. The table entries can be addressed using row and column names or numbers. The concepts of object oriented programming are helpful in understanding tables.
</p>Richard Johnsonhttp://www.mathworks.com/matlabcentral/fileexchange/authors/6765MATLAB 8.3 (R2014a)MATLABfalsetag:www.mathworks.com,2005:FileInfo/475362014-08-13T21:49:12Z2014-09-01T06:00:58Zcrobarcro/mcode-cpp-utilitiesC++ class wrapper and utilities<p>Header file with C++ class wrapper and other related utilities for creating mex interfaces to C++ objects.
<br />This submission expands on the work done by Oliver Woodford on safely wrapping a persistent C++ object in a classdef wrapper. The supplied header file simplifies the creation of interfaces by providing some preprocessor macros, and a set of utility functions for performing argument checking, conversion between Matlab data types and std data types etc.
<br />A base matlab class (cppinterface.m) is supplied to simplify the creation of your wrapper. This is intended to be subclassed by your classdef interface class.</p>
<p>An example is also provided of allowing two wrapped C++ object to communicate with each other directly through access to their pointers.</p>Richard Crozierhttp://www.mathworks.com/matlabcentral/fileexchange/authors/34660MATLAB 8.0 (R2012b)MATLABRequires a C++ compiler38964falsetag:www.mathworks.com,2005:FileInfo/383162012-09-24T15:41:56Z2014-08-26T15:38:20ZObject oriented program demo: animated traffic lights on road intersectionsimple classes and superclass are used to arrange flexible object oriented programming environment<p>Only 31 lines of code in start.m is used to control animated traffic lights on road intersection. LampSuperclass and three clases (trafficLamp, tLamps, map) are used in program. Classes define (1) single Red-Yellow-Green traffic lamp, (2) set of four lamps (North, South, East, West direction) and (3) map of street intersection. Menu is used to change the mode of traffic light operation.</p>Bogumila & Zbigniew MROZEKhttp://www.mathworks.com/matlabcentral/fileexchange/authors/6128MATLAB 8.0 (R2012b)MATLABtested with MATLAB 2014afalsetag:www.mathworks.com,2005:FileInfo/356902012-03-16T13:44:15Z2014-07-19T06:00:18Zmatlab-ClassInheritanceBrowserA tool for managing and organizing classes, with a simple interface and (optional) tree diagram<p>This is version 0.5.6 of Class Inheritance Browser, originally released @ <a href="http://www.mathworks.com/matlabcentral/fileexchange/27633">http://www.mathworks.com/matlabcentral/fileexchange/27633</a>.
<br />
<br />This tool searches a given directory and populates a browser window with pertinent information about each discovered class, including properties, methods, and superclasses. Other useful features include opening a class definition file from the browser window, opening a file to the line where a certain method is defined, and printing property help to the console.
<br />
<br />Additionally, if the Bioinformatics Toolbox is installed, a tree diagram will be displayed that visualizes inheritance relationships between all Matlab classes found.
<br />
<br />Originally written as a project for Engineering 177, Advanced Matlab Programming, Spring 2010, Professor Andrew Packard, University of California, Berkeley.
<br />You can fork this code @ <a href="https://github.com/kotowicz/matlab-ClassInheritanceBrowser">https://github.com/kotowicz/matlab-ClassInheritanceBrowser</a></p>Andreashttp://www.mathworks.com/matlabcentral/fileexchange/authors/104589MATLAB 7.9 (R2009b)MATLABfalsetag:www.mathworks.com,2005:FileInfo/470252014-06-21T15:01:21Z2014-06-30T22:53:38ZcircVBufcircular vector buffer (constant+fast performance, double buffered)<p>circVBuf class defines a circular double buffered vector buffer
<br />* newest vector has the highest index
<br />* oldest vector has the lowest index
<br />* append adds new vectors at the 'right side' of the buffer
<br />* current buffer always accessable as a complete single subarray buf(fst:lst)
<br />
<br />specials:
<br />* any matrix operations at any time possible !
<br />* time required for appending is independent on buffer status !
<br />* index 'new' indicates the start of last appended vectors
<br />
<br />The main idea of this circular buffer is constant performance (=> double buffering) and avoiding copy operations when using the buffer in a program.
<br />Check the screenshot to see, that this circular buffer has advantages if the buffer is large, but the size of data to append each time is small as the performance of circVBuf does NOT depend on the buffer size, compared to a simple copy buffer.
<br />
<br />The double buffering garanties a predictive time for an append depending on the data to append in any situation. In future this class shall give you a choice for double buffering yes or no - things will speedup, if you do not need the garantied time.</p>
<p> example 1
<br />create a circular vector buffer
<br /> bufferSz = 1000;
<br /> vectorLen= 7;
<br /> cvbuf = circVBuf(int64(bufferSz),int64(vectorLen));</p>
<p> example 2
<br />fill buffer with 99 vectors
<br /> vecs = zeros(99,vectorLen,'double');
<br /> cvbuf.append(vecs);</p>
<p> example 3
<br />loop over lastly appended vectors of a circVBuf:
<br /> new = cvbuf.new;
<br /> lst = cvbuf.lst;
<br /> for ix=new:lst
<br /> vec(:) = cvbuf.raw(:,ix);
<br /> end</p>
<p> example 4
<br />direct array operation on lastly appended vectors in the buffer (no copy => fast)
<br /> new = cvbuf.new;
<br /> lst = cvbuf.lst;
<br /> mean = mean(cvbuf.raw(3:7,new:lst));</p>
<p> example 5
<br />MATLAB makes copies of arrays only when the data referred to changes (this is called copy on write or lazy copying). As long as the first index is fixed, the following should not result in a copy and should be of same speed as example 4 even for large arrays:
<br /> new = cvbuf.new;
<br /> lst = cvbuf.lst;
<br /> vbuf3 = cvbuf.raw(3,new:lst);
<br /> mean(vbuf3);
<br />
<br />For comparison more append-types are added (appendType is argument of constructor):
<br />0: default (double buffering, move fst/lst with each append)
<br />1: simply copy always all -- buf = [buf(2:end,:); vecs(:,:)] (fst == 1 always)
<br />2: copy all into old buffer, if end of buffer reached (fst == 1 always)
<br />3: copy-all into new buffer, if end of buffer reached (fst == 1 always) </p>
<p>Please comment concerning performance and other issues.
<br />Code generation should work.</p>Jens Henrik GĂ¶bberthttp://www.mathworks.com/matlabcentral/fileexchange/authors/463918MATLAB 8.3 (R2014a)MATLABShould work since MATLAB 2008a as this version introduced the required handle class.falsetag:www.mathworks.com,2005:FileInfo/459412014-03-19T15:45:52Z2014-06-11T06:00:22ZConstructor for function_handlesCreates evaluable function handles for any function, possibly outside the MATLAB search path<p>If you ever found yourself in a situation where you could not or didn't want to add a directory to the MATLAB search path, but still needed speedy access to a function in that directory, this file is for you.
<br />In such cases, having to change directories to gain access to the function is not the best solution: you'd always have to take care to change the current path back to what it was (even on error). Moreover, performance in those cases can be poor if you have to call this function very often.</p>
<p>FUNCTION_HANDLE allows you to create function handles which can successfully be evaluated without loss of performance, even if the function the handle points to is not on the MATLAB search path. </p>
<p>While there often are better ways to accomplish this sort of task (package directories, symbolic links, etc.), there are a few niche cases where these solutions are simply more involved than using this FUNCTION_HANDLE constructor.</p>
<p>Note that FUNCTION_HANDLE overloads a function present in standard MATLAB. This 'native' function is nothing more than documentation (linked to in the help for this constructor) and an error message which says that you cannot use the function to construct handles. As this is exactly what FUNCTION_HANDLE implements, this shadowing is desirable.</p>
<p>Example session: </p>
<p> >> F = function_handle('./path/to/function/myFcn.m')
<br /> F =
<br /> @myFcn</p>
<p> >> A = function_handle(...
<br /> {@cos, '../dir/not/on/path/myFunction.m'})
<br /> A =
<br /> @cos @myFunction</p>
<p> >> A{1}(pi)
<br /> ans =
<br /> -1 </p>
<p> >> functions(A{1})
<br /> ans =
<br /> function: 'min'
<br /> type: 'simple'
<br /> file: ''</p>
<p> >> functions(A{2})
<br /> ans =
<br /> function: 'myFunction'
<br /> type: 'simple'
<br /> file: '/fullpath/dir/not/on/path/myFunction.m'
</p>Rody Oldenhuishttp://www.mathworks.com/matlabcentral/fileexchange/authors/45753MATLAB 7.10 (R2010a)falsetag:www.mathworks.com,2005:FileInfo/278432010-06-06T19:46:15Z2014-04-09T13:58:02ZArduino IO package: Slides and ExamplesSlides for the webinar: "Learning Basic Mechatronics Concepts Using the Arduino Board and MATLAB".<p>This zip file contains the slides (and some MATLAB examples) used for this webinar: </p>
<p><a href="http://www.mathworks.com/videos/learning-basic-mechatronics-concepts-using-the-arduino-board-and-matlab-81717.html">http://www.mathworks.com/videos/learning-basic-mechatronics-concepts-using-the-arduino-board-and-matlab-81717.html</a></p>
<p>The webinar introduces the ArduinoIO package, which allows the user to perform Analog and Digital Input and Output, as well as to control DC, Servo and Stepper Motors interactively from the MATLAB command window, without having to write, debug, compile, upload and run C programs.</p>
<p>The examples included is this file are taken from the "example" folder of the Arduino IO package.</p>
<p>NOTE: You can download the Arduino IO package from here: <a href="http://www.mathworks.com/matlabcentral/fileexchange/32374">http://www.mathworks.com/matlabcentral/fileexchange/32374</a>
</p>Giampiero Campahttp://www.mathworks.com/matlabcentral/fileexchange/authors/76178MATLAB 7.10 (R2010a)false