<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: When to Create Classes in MATLAB</title>
	<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Mon, 23 Nov 2009 00:54:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Daniel Carleton</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30238</link>
		<dc:creator>Daniel Carleton</dc:creator>
		<pubDate>Mon, 27 Apr 2009 19:09:50 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30238</guid>
		<description>Nausheen,

It's also worth noting that when I use a value type for MyList I get extremely poor performance as you predicted.

&#62;&#62; list_compare            
Elapsed time is 20.858983 seconds.
Elapsed time is 0.000622 seconds.

It's very large compared with inheriting from handle, but inheriting from handle is still inexplicably slow as per my post above.

Thanks,

- Daniel</description>
		<content:encoded><![CDATA[<p>Nausheen,</p>
<p>It&#8217;s also worth noting that when I use a value type for MyList I get extremely poor performance as you predicted.</p>
<p>&gt;&gt; list_compare<br />
Elapsed time is 20.858983 seconds.<br />
Elapsed time is 0.000622 seconds.</p>
<p>It&#8217;s very large compared with inheriting from handle, but inheriting from handle is still inexplicably slow as per my post above.</p>
<p>Thanks,</p>
<p>- Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Carleton</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30231</link>
		<dc:creator>Daniel Carleton</dc:creator>
		<pubDate>Sat, 25 Apr 2009 23:05:55 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30231</guid>
		<description>Hello Nausheen,

In my post I think I included the wrong code.  My list is indeed a subclass of handle, and shows the performance characteristics from my last post:

&#62;&#62; list_compare
Elapsed time is 0.083423 seconds.
Elapsed time is 0.000395 seconds.

Any other ideas?  Our application is severely bottlenecked by poor list performance.  I wrote a detailed post below.

http://dacc.exaptic.com/2009/01/list-class-in-matlab-oo-overhead-pass-by-strategies/

Thanks,

- Daniel</description>
		<content:encoded><![CDATA[<p>Hello Nausheen,</p>
<p>In my post I think I included the wrong code.  My list is indeed a subclass of handle, and shows the performance characteristics from my last post:</p>
<p>&gt;&gt; list_compare<br />
Elapsed time is 0.083423 seconds.<br />
Elapsed time is 0.000395 seconds.</p>
<p>Any other ideas?  Our application is severely bottlenecked by poor list performance.  I wrote a detailed post below.</p>
<p><a href="http://dacc.exaptic.com/2009/01/list-class-in-matlab-oo-overhead-pass-by-strategies/" rel="nofollow">http://dacc.exaptic.com/2009/01/list-class-in-matlab-oo-overhead-pass-by-strategies/</a></p>
<p>Thanks,</p>
<p>- Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30215</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 20 Apr 2009 12:14:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30215</guid>
		<description>Francisco-

It is intended behavior that package contents are not automatically imported or on the path.  There is no intention to not allow users to write methods for builtin classes, though, if you override one of the builtin methods, some functionality may no longer work as intended.

I recommend you read the documentation for more information about how to work with packages.

--Loren</description>
		<content:encoded><![CDATA[<p>Francisco-</p>
<p>It is intended behavior that package contents are not automatically imported or on the path.  There is no intention to not allow users to write methods for builtin classes, though, if you override one of the builtin methods, some functionality may no longer work as intended.</p>
<p>I recommend you read the documentation for more information about how to work with packages.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francisco Valverde</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30214</link>
		<dc:creator>Francisco Valverde</dc:creator>
		<pubDate>Mon, 20 Apr 2009 10:51:08 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30214</guid>
		<description>Hello Loren,

Regarding #23, I would like to subclass 'double' to a +mypackage/@double to redefine operators such as ctranspose and mtimes.

But unless the @double dir lies directly in one of the dirs in *path*, Matlab seems unable to find it. E.g. 'which mtimes' will not find +mypagkage/@double/mtimes.m even if it exists and is declared in +mypackage/@double/double.m

Is that intended behaviour to prevent the users' monkeying too much with builtin classes?

TIA
F.Valverde</description>
		<content:encoded><![CDATA[<p>Hello Loren,</p>
<p>Regarding #23, I would like to subclass &#8216;double&#8217; to a +mypackage/@double to redefine operators such as ctranspose and mtimes.</p>
<p>But unless the @double dir lies directly in one of the dirs in *path*, Matlab seems unable to find it. E.g. &#8216;which mtimes&#8217; will not find +mypagkage/@double/mtimes.m even if it exists and is declared in +mypackage/@double/double.m</p>
<p>Is that intended behaviour to prevent the users&#8217; monkeying too much with builtin classes?</p>
<p>TIA<br />
F.Valverde</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jiro</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30203</link>
		<dc:creator>Jiro</dc:creator>
		<pubDate>Thu, 09 Apr 2009 11:53:25 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30203</guid>
		<description>Rainer,

If "anothertype" is a user-defined MATLAB class, you can use the InferiorClasses attribute on your "mytype" to make it have higher precedence than "anothertype".

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brf5okb-1.html</description>
		<content:encoded><![CDATA[<p>Rainer,</p>
<p>If &#8220;anothertype&#8221; is a user-defined MATLAB class, you can use the InferiorClasses attribute on your &#8220;mytype&#8221; to make it have higher precedence than &#8220;anothertype&#8221;.</p>
<p><a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brf5okb-1.html" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brf5okb-1.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rainer</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30202</link>
		<dc:creator>Rainer</dc:creator>
		<pubDate>Thu, 09 Apr 2009 02:09:20 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30202</guid>
		<description>Hello Loren,

I want a new class (mytype) to seamlessly interface with existing classes (builtin, e.g. "double" and non-builtin datatypes from existing other 3rd party toolboxes, e.g. "anothertype").
This seems easy to achieve when the first argument of a function is my new datatype e.g.

a=mytype(10);
b=anothertype(12);
a+b  % calls @mytype/plus
b+a  % calls @anothertype/plus -- problem here

The last line is undesirable for me, since I would like to overload the plus function in such a way that @mytype/plus gets called if ANY of its arguments is of type "mytype".
If I am not starting to modify the code of @anothertype/plus (which I do not want to touch), I did not see a possibility to influence the behaviour.

Is there any possibility to influence which function gets called for which combination of datatypes? 

Thanks for any help in clarifying this,

    Rainer</description>
		<content:encoded><![CDATA[<p>Hello Loren,</p>
<p>I want a new class (mytype) to seamlessly interface with existing classes (builtin, e.g. &#8220;double&#8221; and non-builtin datatypes from existing other 3rd party toolboxes, e.g. &#8220;anothertype&#8221;).<br />
This seems easy to achieve when the first argument of a function is my new datatype e.g.</p>
<p>a=mytype(10);<br />
b=anothertype(12);<br />
a+b  % calls @mytype/plus<br />
b+a  % calls @anothertype/plus &#8212; problem here</p>
<p>The last line is undesirable for me, since I would like to overload the plus function in such a way that @mytype/plus gets called if ANY of its arguments is of type &#8220;mytype&#8221;.<br />
If I am not starting to modify the code of @anothertype/plus (which I do not want to touch), I did not see a possibility to influence the behaviour.</p>
<p>Is there any possibility to influence which function gets called for which combination of datatypes? </p>
<p>Thanks for any help in clarifying this,</p>
<p>    Rainer</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nausheen Moulana</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30047</link>
		<dc:creator>Nausheen Moulana</dc:creator>
		<pubDate>Wed, 18 Feb 2009 19:01:20 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30047</guid>
		<description>Hi Peter:

Here are some options you have to redefine operations on integers only.

1) You can wrap on overflow by adding your own arithmetic operators for example, a plus method for the uint8 data type.  You can do so by creating and adding a new @uint8 directory to a directory your MATLAB path (..\myDir\@uint8).  In this directory you can add a plus method which contains the following code:
&lt;/pre&gt;
function result = plus(A,B)
result = uint8(mod(double(A)+B,256));
&lt;/pre&gt;
The above is just an example, it doesn't account for error handling and performance.  You can find more information on the function names for MATLAB operators at:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/f1-6624.html
By doing this, you can still use the uint8 command to construct integers but MATLAB will now call your plus method instead of the default method that saturates on overflow.  

2) You can subclass from a built-in integer type and redefine the operations you are interested in.  Here's an example from our documentation:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brgze9_-1.html#brsk0i6


It's generally good to associate different behaviors with different classes.  By using the second approach, you can use uint8 for the default saturate behavior and your own myuint8 class for wrap behavior.  

Nausheen</description>
		<content:encoded><![CDATA[<p>Hi Peter:</p>
<p>Here are some options you have to redefine operations on integers only.</p>
<p>1) You can wrap on overflow by adding your own arithmetic operators for example, a plus method for the uint8 data type.  You can do so by creating and adding a new @uint8 directory to a directory your MATLAB path (..\myDir\@uint8).  In this directory you can add a plus method which contains the following code:

</p><p>function result = plus(A,B)<br />
result = uint8(mod(double(A)+B,256));

</p><p>The above is just an example, it doesn&#8217;t account for error handling and performance.  You can find more information on the function names for MATLAB operators at:<br />
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/f1-6624.html" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/f1-6624.html</a><br />
By doing this, you can still use the uint8 command to construct integers but MATLAB will now call your plus method instead of the default method that saturates on overflow.  </p>
<p>2) You can subclass from a built-in integer type and redefine the operations you are interested in.  Here&#8217;s an example from our documentation:<br />
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brgze9_-1.html#brsk0i6" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brgze9_-1.html#brsk0i6</a></p>
<p>It&#8217;s generally good to associate different behaviors with different classes.  By using the second approach, you can use uint8 for the default saturate behavior and your own myuint8 class for wrap behavior.  </p>
<p>Nausheen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Noronha</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30035</link>
		<dc:creator>Peter Noronha</dc:creator>
		<pubDate>Wed, 11 Feb 2009 19:46:18 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-30035</guid>
		<description>Loren,

In this post you wrote:
"Another reason I may want to create a new type is to extend or redefine operations on an existing type. For example, I may require integer arithmetic to wrap as opposed to saturate (which is what MATLAB does) on overflow."

I am interested in doing exactly this but don't know how to extend or redefine the math operators. If this particular example has been implemented somewhere, could you point me to it?  

I would like to set this (wrap on overflow) as the default behavior for math operators within my MATLAB session for all integer data types without affecting the behavior of these operators for any other data type.  I wonder if this behavioral setting should be something that should be available under MATLAB &#62; Preferences...

Thanks,

Peter</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>In this post you wrote:<br />
&#8220;Another reason I may want to create a new type is to extend or redefine operations on an existing type. For example, I may require integer arithmetic to wrap as opposed to saturate (which is what MATLAB does) on overflow.&#8221;</p>
<p>I am interested in doing exactly this but don&#8217;t know how to extend or redefine the math operators. If this particular example has been implemented somewhere, could you point me to it?  </p>
<p>I would like to set this (wrap on overflow) as the default behavior for math operators within my MATLAB session for all integer data types without affecting the behavior of these operators for any other data type.  I wonder if this behavioral setting should be something that should be available under MATLAB &gt; Preferences&#8230;</p>
<p>Thanks,</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer Black</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-29978</link>
		<dc:creator>Jennifer Black</dc:creator>
		<pubDate>Thu, 22 Jan 2009 19:46:58 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-29978</guid>
		<description>JP,

The code you are referring to with the schema.m files is part of experimental code that is not part of the official MATLAB Class System.  At present, we do not provide support for classes in nested @-directories. However, you can make use of packages to create nesting relationships. 

To create a package directory, use the + symbol as a prefix for the directory name.  Then, within that directory you can place @-directories containing class definitions.  You can also place additional (nested) package directories.

For example, given the following directories:

+pkg1/@Class1
+pkg2/+pkg2/@Class2

Class1 is a class contained within pkg1, and can be instantiated using the syntax:

&#62;&#62; obj = pkg1.Class1;

Class2 is contained within the package pkg2, which is itself nested within pkg1.  To create an instance, use the following syntax:

&#62;&#62; obj = pkg1.pkg2.Class2;

Hope this helps -

Jennifer</description>
		<content:encoded><![CDATA[<p>JP,</p>
<p>The code you are referring to with the schema.m files is part of experimental code that is not part of the official MATLAB Class System.  At present, we do not provide support for classes in nested @-directories. However, you can make use of packages to create nesting relationships. </p>
<p>To create a package directory, use the + symbol as a prefix for the directory name.  Then, within that directory you can place @-directories containing class definitions.  You can also place additional (nested) package directories.</p>
<p>For example, given the following directories:</p>
<p>+pkg1/@Class1<br />
+pkg2/+pkg2/@Class2</p>
<p>Class1 is a class contained within pkg1, and can be instantiated using the syntax:</p>
<p>&gt;&gt; obj = pkg1.Class1;</p>
<p>Class2 is contained within the package pkg2, which is itself nested within pkg1.  To create an instance, use the following syntax:</p>
<p>&gt;&gt; obj = pkg1.pkg2.Class2;</p>
<p>Hope this helps -</p>
<p>Jennifer</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J P Barnard</title>
		<link>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-29970</link>
		<dc:creator>J P Barnard</dc:creator>
		<pubDate>Thu, 22 Jan 2009 07:30:28 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/#comment-29970</guid>
		<description>Hello Loren

Question on nested classes, using the new class syntax: I have noticed such file structures in the MATLAB toolboxes, but in the documentation it is stated that an @ folder with new class syntax will shadow all @folders under it, making them invisible even to the top level class. I have also noticed some schema.m in at the non-@ folders, containing  these nested @ folders. What is the trick, because I cannot get that nesting to work and the documentation is not clear on this aspect?

Cheers

JP</description>
		<content:encoded><![CDATA[<p>Hello Loren</p>
<p>Question on nested classes, using the new class syntax: I have noticed such file structures in the MATLAB toolboxes, but in the documentation it is stated that an @ folder with new class syntax will shadow all @folders under it, making them invisible even to the top level class. I have also noticed some schema.m in at the non-@ folders, containing  these nested @ folders. What is the trick, because I cannot get that nesting to work and the documentation is not clear on this aspect?</p>
<p>Cheers</p>
<p>JP</p>
]]></content:encoded>
	</item>
</channel>
</rss>
