Search
Code Directory
 ASP
 ASP.NET
 C/C++
 CFML
 CGI/PERL
 Delphi
 Development
 Flash
 HTML
 Java
 JavaScript
 Pascal
 PHP
 Python
 SQL
 Tools
 Visual Basic & VB.NET
 XML
New Code
The C# Excel Library 2020.5
dbForge Studio for MySQL 9.0
LinkedIn Clone 2.2
Uber clone Apps 4.0
Cab Booking Script 1.3.2
Airbnb Clone HomestayDNN 3.0
Magento Language switcher 1.2.1
The .Net PDF Library 2020.3.2
IP2Location Geolocation Database 2020.5
ODBC Driver for MailChimp 2.0
ODBC Driver for NetSuite 2.0
ODBC Driver for SQL Azure 3.1
dbForge Schema Compare for Oracle 4.1
dbForge Data Compare for Oracle 5.1
dbForge Studio for Oracle 4.1
Top Code
dbForge Studio for MySQL 8.1
dbForge Studio for Oracle 3.10
dbForge Schema Compare for Oracle 2.7
dbForge Data Compare for Oracle 3.7
IP2Location Geolocation Database 2020.5
azar's knights tour 1.0
PDF Chart Creator DLL
PDF Chart Creator Dynamic Link Library 1.0
Form creator 1.0
FormMail Lite 1.0
SocketTimesheet
BS/1 Professional - Time Billing and Accounting
Online Video Rental Software System Alpha
Bullschmidt ASP Web Database Sample 2.0
Easy PCB Design Software in Java 1.0
Top Rated
phpEnter 5.1.
Single Leg MLM 1.2.1
Azizi search engine script PHP 4.1.10
Paste phpSoftPro 1.4.1
Extreme Injector 3.7
Deals and Discounts Website Script 1.0.2
Solid File System OS edition 5.1
Classified Ad Lister 1.0
Aglowsoft SQL Query Tools 8.2
Invoice Manager by PHPJabbers 3.0
ICPennyBid Penny Auction Script 4.0
PHP Review Script 1.0
ATN Resume Finder 2.0
ATN Site Builder 3.0
Availability Booking Calendar PHP 1.0
On-The-Fly Definition of Custom Matrix Objects 1.0
File ID: 85146






On-The-Fly Definition of Custom Matrix Objects 1.0
Download On-The-Fly Definition of Custom Matrix Objects 1.0http://www.mathworks.comReport Error Link
License: Shareware
File Size: 30.7 KB
Downloads: 5
Submit Rating:
On-The-Fly Definition of Custom Matrix Objects 1.0 Description
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 default

P =

1 3
2 4


Q =

0 1
1 2


R =

4 6
9 11


S =

3 7
4 10

License: Shareware

Related: footprint, Memory, gtgtwhos, bytes, Class, isequaly, dqobjx, dfftx

O/S:BSD, Linux, Solaris, Mac OS X

File Size: 30.7 KB

Downloads: 5



More Similar Code

Creates polaroids of images on the fly for thumbnails in posts. Support for lightbox included. Built on modified Polaroid-o-nizer v0.7.2 sources.

I wanted to mimic the Polaroid look that you can achieve with Google Picasa to add thumbnails to my posts. I found a plugin titled WP-Polaroidonizer that did what I wanted to some extent but it didn't have the right feel to it.

The other problem I have with Polaroid-o-nizer and...



Allows on-the-fly creation of HTML tables in Python. Similar to Table.pm or Table.php.



Open Source Semantic Web Search Engine Software: If two machines anywhere on the web can agree on the same definition of a digital service or digital good, then machine to machine transactions can use this lingua franca to transact on the users...



Creating Assemblies On The Fly Using Code DOM is an useful article for the programmers to learn about the process of generating assemblies with the help of code document object model. Here the author gives details about various classes and gives...



Change Style Sheets On-The-Fly from Page Links is a JavaScript that can change the style sheets of your window without any requirement of coding. Supports different links for different styles. You can click on the links to change the style sheet....



Patches xmms for on the fly recoding id3 tags, m3u playlists, and file names from one encoding to another. Support ID3 tag editing, playlist sorting, encoding autodetection. Configuration available under encodings page of standard xmms preferences.



Creating Datasets on the Fly is an useful tutorial for those who need to know how to sort and filter the database data that are passed to the dataset object. In this tutorial the author clearly shows you how to create a DataSet object and use...



On-the-Fly .NET Compiler - tool or library for compilation CLR language in real time, also in memory, and following execution. This can be used for desktop and web scripting, remote compilation, etc. It's free, written on C# and multiplatform.



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:

...



The OOParLib (Object Oriented Parser Library) is a C++ library for dynamical construction of parser objects (possibly on the fly) through the combination of various tokenizing objects by the help of operators.

User Review for On-The-Fly Definition of Custom Matrix Objects
- required fields
     

Please enter text on the image