Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 32.287.532 Times

On-The-Fly Definition of Custom Matrix Objects 1.0

  Date Added: April 15, 2013  |  Visits: 312

On-The-Fly Definition of Custom Matrix Objects

Report Broken Link
Printer Friendly Version

Product Homepage
Download (18 downloads)

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); @(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

Requirements: No special requirements
Platforms: Matlab
Keyword: Bytes Class Dfftx Dqobjx Footprint Gtgtwhos Isequaly Memory
Users rating: 0/10

License: Shareware Size: 30.72 KB
Development Tools  -  Fast function to save a matrix 1.0
write_matrix_bin(f,m) saves the matrix "m" in a binaryfile "f". write_matrix_bin is a lot faster than the built in function save(), andtakes up much less diskspace than the old "save -v6" which doesn't use compression.write_matrix_bin also...
10 KB  
Development Tools  -  N-dimensional sparse arrays 1.0
The class ndSparse defined in this submission will give a lot of the functionality of N-dimensional sparse arrays for N possibly greater than 2. However, it should really be thought of as a way of starting with an ordinary MATLAB sparse matrix and...
20.48 KB  
Development Tools  -  atrix Products Expressed in Terms of Individual Operands 1.0
This submission defines a class for representing products of matrices (or of any objects that know how to multiply) when it is more efficient to store and manipulate the matrices separately. USAGE: P=ProdCascade({A1,A2,...,An}) This creates an...
10 KB  
Programming  -  bintrees 1.0.0
The bintrees package provides Binary- RedBlack- and AVL-Trees written in Python and Cython. This Classes are much slower than the bulitin.dict class and uses twice as much memory, but they have always sorted keys, and all results of...
92.16 KB  
Computer Information Databases  -  Accuracer Database System 3.01
Accuracer is a compact, embedded, single-file, multi-user (file-server and client/server) cross-platform BDE replacement database with SQL support which is based on a new original BDE alternative database engine that supports the almost all...
7.79 MB  
Utilities  -  uLan Driver 0.7.2
uLan Driver provides 9-bit message oriented communication protocol, which is transferred over RS-485 link. Characters are transferred same way as for RS-232 asynchronous transfer except parity bit, which is used to distinguish between data...
256 KB  
Development Tools  -  splitvar/splicevar 1.0
Saving large (>2 GB) variables using the '-v7.3' flag is terribly slow, especially if the variable is not a simple matrix. If the large variable that is holding you up is a 1-D array, you can use SPLITVAR to break it up into separate variables in...
10 KB  
Development Tools  -  Robust Sparse data types 1.0
The main file in this package, rsparse.m, creates a sparse array object that is a subclass of MATLAB's native sparse data type, but which is robust against certain bugs and errors (present as of R2009b). S=rsparse(varargin) The I/O syntax and...
30.72 KB  
Multimedia  -  inputgui 1.0
INPUTGUI allows a user to set function parameters through an input dialog window. It's meant to be a replacement for INPUT. Among its virtues is that the dialog popup can be overriden either by accepting defaults or by assigning (some of the)...
10 KB  
Automotive Information Databases  -  Accuracer Database System VCL 9.00
Accuracer is a compact, embedded, single-file, multi-user (file-server and client/server) cross-platform BDE replacement database with SQL support based on a new original BDE alternative database engine that supports the almost all TTable, TQuery,...
26.07 MB  
Scripts  -  Freelancer Script 5.05
Main Features: 100% Secured. Email Support (3 Years). FREE Updates (3 Years). Post projects. Featured projects. Private projects. Sealed projects. Edit/delete projects. Select freelancers....
5.49 MB  
Scripts  -  B2B Script 4.20
Main Features: 100% Secured. Email Support (3 Years). FREE Updates (3 Years). Sign-up Account (Registration of account). Lead generation tools (for the sellers). Email verification to...
5.49 MB  
Scripts  -  B2C Script 5.06
Main Features: 100% Secured. Email Support (3 Years). FREE Updates (3 Years). The script comes with totally editable site colors, icons and graphics Multilevel categories allows extensive browsing Admin can change Category ordering or...
5.49 MB  
Scripts  -  Social Networking Script 2.86
Main Features: 100% Secured. Email Support (3 Years). FREE Updates (3 Years). Registration with name, email, password, date of birth etc. User can add multiple school, college, university with start...
5.49 MB  
Scripts  -  Business Networking Script 8.04
Main Features: 100% Secured. Email Support (3 Years). FREE Updates (3 Years). Ajax based interface. Profile creation. Different types of profile. Profile for jobseekers, employers and employed...
5.49 MB  
Development Tools  -  VMP Viewer 1.0
This is a very rudimentary tool to visualize the VMP files generated by BrainVoyager. Useful to share files with people who do not have BV.
10 KB  
Development Tools  -  Sending reports and timestamped file by emailing 1.0
main executing reference usage:[1] usage_send_mail.mIllustrates email sending with multiple separate files or single timestamped tar file. Attachment failure is properly handled, with continuation of report emailing without the attachment.[2]...
768 KB  
Development Tools  -  IrisMVC 2.0 rc1
IrisMVC is an OOP PHP framework that developers can use as a strong and secure foundation to build on various web applications following the Model-View-Controller (MVC) pattern. It provides the basic functionality developers need, without...
51.2 KB  
Development Tools  -  7-Zip for Script 4.42
7-Zip is a file archiver with a high compression ratio.Features:- High compression ratio in new 7z format with LZMA compression- Supported formats:- Packing / unpacking: 7z, ZIP, GZIP, BZIP2 and TAR- Unpacking only: RAR, CAB, ISO, ARJ, LZH, CHM,...
624.64 KB  
Development Tools  -  Barnardextest 1.0
This file, as the Fisher's exact test, performs the exact probability test for a table of frequency data cross-classified according to two categorical variables, each of which has two levels or subcategories (2x2). It is a non-parametric...
10 KB