Scripts Index
Related Topics
Popular Trends
Trending Topics
Tools and Utilities Development Tools  

On-The-Fly Definition of Custom Matrix Objects

download download home home   report broken
important script information
company name:
Matt J
license: Shareware
minimum requirements: MATLAB 7.9 (2009b)
functional limitations:
On-The-Fly Definition of Custom Matrix Objects description


This submission defines a generic class of matrix-like objects called MatrixObj and a subclass called DataObj. Objects of the class are capable of behaving as matrices, but whose math operators (+,-,*,,.*,,etc...) and other methods can be defined/redefined from within any Mfile or even from the command line. This removes the restriction of writing a dedicated classdef file or class directory for every new matrix-type object that a user might wish to create. The class works by storing function handles to the various matrix operator functions (plus, minus, mtimes, mldivide, etc...) in a property of MatrixObj called Ops, which is a structure variable. Hence, one can set the matrix operators as desired simply by setting the fields of Ops to an appropriate function handle. MatrixObj objects are particularly useful when an object needs to be endowed with just a few matrix-like capabilities that are very quickly expressed using anonymous functions or a few short nested functions. This is illustrated in the examples below that deal with creating an efficient version of a DFT matrix. Another advantage of MatrixObj objects is that it is not necessary to issue a "clear classes" command when their Ops methods need to be edited or redefined. The DataObj subclass is a specialized version of MatrixObj well-suited for mimicking/modifying the behavior of existing MATLAB numeric data types. Its Ops property contains default methods appropriate to existing data types, but which can be selectively overwritten. Example 4 below illustrates its use.EXAMPLE 1: Implementing fft() in operator form. As is well-known, the operation fft(x) can be represented as a matrix-vector multiplication. If you have the Signal Processing Toolbox, the relevant matrix can be generated using the DFTMTX function. Otherwise, it can be generated as follows, d=2500; Q=fft(eye(d)); %DFT matrix - 2500x2500 The operation fft(x) is equivalent to Q*x, but this is a slow way to perform the operation, x=rand(d); tic; y0=Q*x; toc %Elapsed time is 3.595847 seconds. However, using the MatrixObj class, we can quickly create an object Qobj which can transform x using the same matrix multiplication syntax, Qobj*x, but which uses fft() under the hood, with all of its advantages in speed, Qobj=MatrixObj; Qobj.Ops.mtimes=@(obj,z) fft(z); %set the mtimes method in 1 line!! tic; y1=Qobj*x; toc %Elapsed time is 0.212282 seconds. tic; y2=fft(x); toc %Elapsed time is 0.212496 seconds. isequal(y1,y2); % =1 And of of course, the memory footprint of Qobj is far less than for the full matrix Q >>whos Q Qobj Name Size Bytes Class Attributes Q 2500x2500 100000000 double complex Qobj 1x1 4412 MatrixObj EXAMPLE 2: Continuing with Example 1, suppose I now decide that I still want Qobj to represent an fft() operation, but that it be normalized to satisfy Parseval's theorem. A simple on-the-fly redefinition of mtimes() can accomplish this. Qobj.Ops.mtimes=@(obj,z) (1/sqrt(numel(z)))*fft(z); x=rand(d,1); TestParseval=[norm(x), norm(Qobj*x)], % =[28.2807, 28.2807] EXAMPLE 3: Continuing with Example 2, let us now look at how to give Qobj a ctranspose method so that Qobj' is defined. Because Qobj satisfies Parseval's theorem, Qobj' is its inverse. A one-line definition can be made using the Trans property, Qobj.Trans.mtimes=@(obj,z) sqrt(numel(z))*ifft(z) ; The code below verifies that the ctranpose operation has various anticipated properties, TestParseval=[norm(x), norm(Qobj'*x)], % =[28.2807, 28.2807] AdjointOfAdjoint=isequal(Qobj*x, (Qobj')'*x), % =1 InversionerrorLeft=norm(x- Qobj'*(Qobj*x)), % =8.4315e-015 InversionerrorRight=norm(x- Qobj*(Qobj'*x)), % =7.9086e-015 EXAMPLE 4:The following is an example of the DataObj subclass. Here, we use it to create a specialized array type which invokes bsxfun() for certain operations. This can be a useful way of circumventing bsxfun's lengthy functional syntax. Other operations like mtimes have default implementations. P=DataObj; P.Data=[1,2;3,4].', P.Ops.minus=@(A,B) bsxfun(@minus,A,B); P.Ops.plus= @(A,B) bsxfun(@plus,A,B); Q=P-[1,2], R=P+[3;7], S=P*Q, %This uses a natural defaultP = 1 3 2 4 Q = 0 1 1 2 R = 4 6 9 11 S = 3 7 4 10



Relates:
Class - Memory - Bytes - Footprint - Gtgtwhos - Isequaly - Dqobjx - Dfftx
Similar scripts
Rob Keyboard (Popularity: ) : This plugin is produced for holding on keyboard when pairing program. You can type "shift ctrl K" to lock intellJ by a Dialog with amusing words. You can lock intellJ by password, with configging password enabled.At first, you should add ...
CIE Coordinate Calculator (Popularity: ) : This software is for calculating the CIE chromaticity co-ordinates of phosphor materials using the photo luminescence data. The software also shows the position of the co-ordinates in chromaticity diagram and expected color of the material. Please note that the color ...
New Dream Coder for Oracle (Popularity: ) : This tool is an code generator for Oracle. While fetching large tables this tool reduces usage of memory. Some features of this tool are, it has new password ecryption, procedure builder, session monitor, SQL templates etc., It increases execution times ...
Foreign Exchange Options (Popularity: ) : fxoptions( S0, X, rd, rf, T, vol, style)Valuation of European and American call and put options on foreign exchange using Garman-Kohlhagen model.European option prices are given by an exact formula (Garman-Kohlhagen).American option prices are approximated using both binomial and trinomial ...
Anti Cut and Paste (Popularity: ) : This utility is helpful for programmers that allows them to search programming language source code's text fragments which have been copied and pasted. Some key features of this tool are, this tool supports both command line and Graphical User Interface ...
AC Protect Standard (Popularity: ) : This utility is used for avoiding hackers from cracking your software using special techniques called anti crack. It works with all windows platforms. Some features of this tool are, this tool compresses ocx, scr, exe, dll and more, dynamic encrypt ...
VBcodePrint (Popularity: ) : This Add-In to Microsoft Visual Basic 6 significantly enhances its source code printing capabilities. You can print any part of your VB project's source code from within the VB's development environment. / You can create and save your own output ...
Use Matlab Editor to Write and Run Ansys Program. (Popularity: ) : You don't have to switch your screen between Matlab, Ansys and UltraEdit or PSPad anymore, when you doing FEM-Analysis.You can use MEditor to write your Ansys APDL program and use the excellent feature of MEditor to structure your Code: Cell-Function, ...
Bokai Barcode Image generator (Popularity: ) : This tool is used for barcode generator and which has an ActiveX control for printing barcodes. This tool contains more than twenty five barcode types. This tool supports only ActiveX control programs. Users can customize barcode parameters and design of ...
VBAcodePrint (Popularity: ) : This add-in enables you to print Microsoft VBA source code in color of your applications across the entire Microsoft Office 2000 suite of applications: Word, Excel, Outlook, Access, PowerPoint, and FrontPage and any other VBA enabled software. / You can ...
User reviews

Write a review:
1 2 3 4 5 6 7 8 9 10
1=poor 10=excellent
Write review*
Your name*
Email*
  (Comments are moderated, and will not appear on this site until the editor has approved them)
 
Similar Software
SecuBox for Pocket PC (Popularity: ) : On-the-fly encryption of sensitive data stored on Windows Mobile phone and its media cards. Creates an encrypted volume that looks and feels like a Windows Mobile storage card. Data written to this card is transparently encrypted with AES 256-bit algorithm. ...
Formulator.NET (Popularity: ) : Formulator.NET is a robust Form Builder that enables you to create a wide range of forms on-the-fly for Internet and Intranet websites. Create Web forms easily with the Form Wizard, and customize the logic for how your administrative users manage ...
StrongDisk Pro (Popularity: ) : StrongDisk Pro protects sensitive data on your notebook or PC. It creates virtual encrypted disks, which work as common disks. All content of these disks is encrypting on-the-fly with strong crypto-algorithms. To mount disk a password and an external key ...
Encrypted Briefcase Personal (Popularity: ) : Encrypted Briefcase Personal(EBP) allows you to hide folders and encrypt files with on-the-fly AES encryption. Just create one or more encrypted briefcases from local folders and move your sensitive files into the specified folder and they will be encrypted/decrypted in ...
Arctor File Repository (Popularity: ) : Arctor is an easy-to-use and powerful file based backup solution, offering fast, reliable backup and version management. It can quickly and easily restore your files in the event of accidental loss or hardware failures. With Arctor, you are able to ...
Arctor File Backup (Popularity: ) : Arctor is an easy-to-use and powerful file backup solution, offering fast, reliable backup and version management. It can quickly and easily restore your files in the event of accidental loss or hardware failures. With Arctor, you are able to set ...
Go FTP FREE (Popularity: ) : GoFTP is a FTP client that uses special "buffer overstuffing" technology and on-the-fly compression to achieve speeds 3x of other multi-threaded FTP programs. It supports encryption including SFTP and FTPS. It has all of the features of the leading FTP ...
SecuInHand Professional (Popularity: ) : SecuInHand is a powerful file encryption, and folder and registry access-protection application consisting of access filtering module, on-the-fly encryption/decryption module, and trusted programs access control module. The access-filtering module provides access filtering for protected files and registries such that only ...
DirCryptHide (Popularity: ) : Any number of folders with all subfolders (even on different drives) can be moved in a highly scripted container file (created with TrueCrypt). This can be opened with password/USB-Device if needed, this container file will mount as another drive. When ...
myLittleWriter (Popularity: ) : myLittleWriter allows you to easily create RTF files on the fly. You can use myLittleWriter in your ASP.NET pages, in your classic ASP pages or in your .NET applications. Best of all, you DON'T NEED to have MS Word installed ...
ad


Rate me
supported os
Linux
Mac OSX
Macintosh
Win All, BSD, Solaris
stats
downloads 1
version 1.0
size in Kb 31
popularity   
662/377345
user rating 0/10
New Scripts
Popular Scripts
Latest Reviews