<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3128290857071255389</id><updated>2011-07-07T21:11:33.791-07:00</updated><title type='text'>Replicate And Tile</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://repmat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://repmat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>dg</name><uri>http://www.blogger.com/profile/14091083649493610193</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3128290857071255389.post-3176492253265621050</id><published>2009-11-03T17:28:00.000-08:00</published><updated>2009-11-03T17:42:07.429-08:00</updated><title type='text'>Troubleshooting Matlab and MySQL</title><content type='html'>Matlab's got a half-decent &lt;a href="http://www.mathworks.com/products/database/"&gt;database toolbox&lt;/a&gt;, but it's usually a huge pain to get working at first. &lt;br /&gt;&lt;br /&gt;You can see some other blogs &lt;a href="http://www.etf-central.com/using-matlab%2526%2523039;s-database-toolbox-mysql-connector/j-214"&gt;here&lt;/a&gt; or &lt;a href="http://desk.stinkpot.org:8080/tricks/index.php/2006/02/how-to-get-matlab-to-talk-to-mysql/"&gt;here&lt;/a&gt; for the code but one thing that hasn't been pointed out clearly enough is how bad the error reporting is.&lt;br /&gt;&lt;br /&gt;Take this, for example:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;driver = 'com.mysql.jdbc.Driver';&lt;br /&gt;driver = which('mysql-connector-java-5.0.8-bin.jar');&lt;br /&gt;javaaddpath(driver);&lt;br /&gt;host = 'loclhost';&lt;br /&gt;port = 3306;&lt;br /&gt;dbname = 'MyTestDb';&lt;br /&gt;user = 'tester';&lt;br /&gt;password = 'god'; %The Plague wouldn't like this...&lt;br /&gt;url = ['jdbc:mysql://' host ':' num2str(port) '/' dbname];&lt;br /&gt;db = database(dbname, user, password, driver, url)&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Looks ok, but returns the error &lt;span style="font-weight:bold;"&gt;JDBC Driver Error: com.mysql.jdbc.Driver. Driver Not Found/Loaded&lt;/span&gt;. Which of course would send any normal person off on a wild goose chase -- Is the jar file corrupted? Is there supposed to be a 64-bit version? Maybe I should use the fixed java class path instead of the dynamic one?&lt;br /&gt;&lt;br /&gt;But it's just a stupid typo: 'loclhost' instead of 'localhost'. Most stupid connection string mistakes you can make (user names, port numbers, etc) will result in the same missing driver error.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3128290857071255389-3176492253265621050?l=repmat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://repmat.blogspot.com/feeds/3176492253265621050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://repmat.blogspot.com/2009/11/troubleshooting-matlab-and-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default/3176492253265621050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default/3176492253265621050'/><link rel='alternate' type='text/html' href='http://repmat.blogspot.com/2009/11/troubleshooting-matlab-and-mysql.html' title='Troubleshooting Matlab and MySQL'/><author><name>dg</name><uri>http://www.blogger.com/profile/14091083649493610193</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3128290857071255389.post-5807340514270087370</id><published>2009-04-15T14:41:00.001-07:00</published><updated>2009-04-15T15:43:28.688-07:00</updated><title type='text'>Unique handles</title><content type='html'>I was surprised today to find that there's no built-in UNIQUE function for arrays of handle derived objects.&lt;br /&gt;&lt;blockquote&gt;&gt;&gt; X = [myClass(); myClass(); myClass()]; %Three unique instances of myClass&lt;br /&gt;&gt;&gt; X = [X X]; %Double up -- two copies of each unique instance&lt;br /&gt;&gt;&gt; unique(X)&lt;br /&gt;&lt;br /&gt;??? Error using ==&gt; double&lt;br /&gt;Conversion to double from class1 is not possible.&lt;br /&gt;&lt;br /&gt;Error in ==&gt; unique at 92&lt;br /&gt;      a = double(a);&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;When you're working with arrays of handle graphics handles, handles are actually doubles, so any standard array-based function (e.g. permute, kron, ismember) will work on an array of handle graphics handles. This works because you're actually working with each graphics object's &lt;a href="http://en.wikipedia.org/wiki/Guid"&gt;globally unique identifier (GUID)&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The more recently released handle objects are represented by doubles in the same way; it's just that the underlying GUID is abstracted away so that its actual numeric value is never seen. This is a nice abstraction in some ways: myObj.Prop = val is much easier to read and write than set(myObj, 'Prop', val).&lt;br /&gt;&lt;br /&gt;The fact that handle objects are still represented as GUIDs in the Matlab interpreter is evident when you check the built-in handle methods:&lt;br /&gt;&lt;blockquote&gt; &gt;&gt; methods handle&lt;br /&gt;Methods for class handle:&lt;br /&gt;&lt;br /&gt;addlistener  findobj      gt           lt           &lt;br /&gt;delete       findprop     isvalid      ne           &lt;br /&gt;eq           ge           le           notify&lt;br /&gt;&lt;/blockquote&gt;The relational operators gt, lt, ne, eq, ge, and le operate by calling the appropriate comparators on the GUIDs themselves. For some reason there are more handle methods listed in the &lt;a href="http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/handle.html&amp;http://www.mathworks.com/support/functions/alpha_list.html?sec=4"&gt;documentation&lt;/a&gt; that aren't returned by the methods function: transpose, permute, reshape, and sort. Again, since arrays of handle objects are essentially arrays of GUIDs, these functions work exactly how we'd expect. &lt;br /&gt;&lt;br /&gt;Of course, once we've got reshaping and relational operators, we can build most of the other functions we'd need. Here's a quick and dirty unique function:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;function B = uniquehandles (A)&lt;br /&gt;%UNIQUEHANDLES Find unique handle object instances&lt;br /&gt;&lt;br /&gt;A = A(:); %Column vector&lt;br /&gt;A = sort(A);&lt;br /&gt;i = [true; A(1:end-1)~=A(2:end)];&lt;br /&gt;B = A(i);&lt;/blockquote&gt;The problem here is obvious if you check out the code for the built in Matlab unique function: it's dominated by error-checking and code for maintaining dimensional consistency, and I really don't want to duplicate it all. &lt;br /&gt;&lt;br /&gt;The weird thing is that despite the documentation, it seems like almost all array functions work with arrays of handles like repmat, sortrows, num2cell, and mat2cell. Even some of the set functions work: ismember and intersect work, but unique, setdiff, and setxor don't. &lt;br /&gt;&lt;br /&gt;This happens because ismember and intersect are &lt;a href="http://en.wikipedia.org/wiki/Type_polymorphism"&gt;polymorphic&lt;/a&gt;. There isn't a separate handle.ismember function; it "just works" because the GUID basis allows arrays of handles to be treated like numeric arrays. The other set functions attempt to explicitly cast the input array to double, which results in the oh-so-aggravating "cannot convert to double" error.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3128290857071255389-5807340514270087370?l=repmat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://repmat.blogspot.com/feeds/5807340514270087370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://repmat.blogspot.com/2009/04/unique-handles.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default/5807340514270087370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default/5807340514270087370'/><link rel='alternate' type='text/html' href='http://repmat.blogspot.com/2009/04/unique-handles.html' title='Unique handles'/><author><name>dg</name><uri>http://www.blogger.com/profile/14091083649493610193</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3128290857071255389.post-4322366404542662603</id><published>2009-03-17T17:07:00.000-07:00</published><updated>2009-03-17T18:45:35.536-07:00</updated><title type='text'>Matlab OOP Oversight </title><content type='html'>&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;I've been using Matlab full-time for about 3 years now, and using its new OOP features intensively for about 6 months. It's quite nice, and simplifies a lot of coding, but there's one big glaring oversight in the way Matlab treats arrays of objects. I sat down the other night to write a dorky little rant about it that I could post to the Matlab newsgroup, but it turned into a bit of an essay, complete with citations and sample code, so I made a dorky little blog out of the thing.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		A:link { so-language: zxx } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Let me first quote from the &lt;a href="http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_oop/brglmxp.html&amp;amp;http://www.mathworks.com/access/helpdesk/help/techdoc/helptoc.html#brgxch1"&gt;Matlab documentation&lt;/a&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		H3 { margin-bottom: 0.08in } 		H4 { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Times New Roman,serif;"&gt;&lt;span style="font-size:130%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;h3&gt;&lt;span style=";font-family:Times New Roman,serif;font-size:78%;"  &gt;Super and Subclass Behavior&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;Subclass objects behave like objects of the super class because they are specializations of the super class. This fact facilitates the development of related classes that behave similarly, but are implemented differently.  &lt;/span&gt;&lt;/p&gt; &lt;h4&gt;&lt;span style="font-size:78%;"&gt;&lt;a name="brgxcjl"&gt;&lt;/a&gt;A Subclass Object Is A Superclass Object&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;You usually can describe the relationship between an object of a subclass and an object of its superclass with a statement like:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;The subclass is a superclass . For example: An Engineer is an Employee.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;This relationship implies that objects belonging to a subclass have the same properties, methods, and events of the superclass, as well as any new features defined by the subclass.  &lt;/span&gt;&lt;/p&gt; &lt;h4&gt;&lt;span style="font-size:78%;"&gt;&lt;a name="brgxclw"&gt;&lt;/a&gt;A Subclass Object Can be Treated Like a Superclass Object&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;You can pass a subclass object to a super class method, but you can access only those properties that are defined in the super class. This behavior enables you to modify the subclasses without affecting the super class.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;Two points about super and subclass behavior to keep in mind are:&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:78%;"&gt;Methods defined in the super class can operate on objects 	belonging to the subclass.  	&lt;/span&gt;&lt;/p&gt; 	&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:78%;"&gt;Methods defined by the subclass cannot operate on objects 	belonging to the super class.&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-size:78%;"&gt;Therefore, you can treat an &lt;tt&gt;Engineer&lt;/tt&gt; object like any other &lt;tt&gt;Employee&lt;/tt&gt; object, but an &lt;tt&gt;Employee&lt;/tt&gt; object cannot pass for an &lt;tt&gt;Engineer&lt;/tt&gt; object.&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;This is NOT true in the case of arrays of objects. Consider the following pseudo code:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New,monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New,monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;E1 = [Employee(), Employee()];&lt;br /&gt;&lt;br /&gt;E1 =           1x2 Employee&lt;br /&gt;&lt;br /&gt;E2 = [Employee(), Engineer()];&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;??? Error using ==&gt; horzcat The following error occurred converting from Engineer to Employee: &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Error using ==&gt; Employee &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Too many input arguments.&lt;/span&gt;&lt;/span&gt; &lt;p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		A:link { so-language: zxx } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;E2 &lt;b&gt;should&lt;/b&gt; be an array of Employee objects, but the attempted concatenation raises an error. Despite what the documentation says, the Engineer object CANNOT be treated like any other Employee object.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-weight: normal;font-size:85%;" &gt;There's a &lt;a href="http://www.mathworks.com/support/solutions/data/1-6K5PAO.html?solution=1-6K5PAO"&gt;Matlab technical solution&lt;/a&gt; that suggests two possible work arounds to this issue:&lt;/span&gt;&lt;/p&gt; &lt;ol&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-weight: normal;font-size:85%;" &gt;Create 	a converter method that casts the sub-class instance into a 	superclass instance&lt;/span&gt;&lt;/p&gt; 	&lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-weight: normal;font-size:85%;" &gt;Use 	cell arrays instead of arrays.&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ol&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-weight: normal;font-size:85%;" &gt;Option 1 is simply unviable -- casting to a superclass object loses all of the data specific to the subclass, and &lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;obviates the entire point of subclassing.&lt;/b&gt;&lt;/span&gt;&lt;span style="font-weight: normal;font-size:85%;" &gt; Option 2 is bad idea for reasons I'll go into further on.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:85%;"&gt;This issue came up a year ago or so in the newsgroup, where Steve Lord &lt;a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/170236#435366"&gt;wrote&lt;/a&gt;, in response to somebody troubled by the same problem: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="color: rgb(153, 153, 153);"&gt;&lt;span style="color: rgb(0, 0, 0);font-size:78%;" &gt;"Greg " &lt;greg9504@removeforspam.hotmail.com&gt; wrote in message&lt;br /&gt;news:g1sb1g$9tu$1@fred.mathworks.com...&lt;br /&gt;&gt; Well the work around is to use a cell array instead.&lt;br /&gt;&lt;br /&gt;Yes.&lt;br /&gt;&lt;br /&gt;&gt; Although I feel that two classes sharing the same base class&lt;br /&gt;&gt; should be able to be put in a matrix...&lt;br /&gt;&lt;br /&gt;Let's say that A is an object that is both an animal and a dog, and B is an&lt;br /&gt;object that is both an animal and a cat. Both the dog class and the cat&lt;br /&gt;class have additional properties and/or methods that aren't in the animal&lt;br /&gt;class.&lt;br /&gt;&lt;br /&gt;What class should C = [A; B] be?&lt;br /&gt;&lt;br /&gt;It can't be a dog array, unless you can convert the cat animal B into a dog&lt;br /&gt;(which usually doesn't work too well.)&lt;br /&gt;It can't be a cat array, since you can't convert A into a cat.&lt;br /&gt;It can't be an animal array either, since each of A and B have pieces that&lt;br /&gt;aren't in the animal class that would have to be removed to fit them into an&lt;br /&gt;animal array.&lt;br /&gt;&lt;br /&gt;It doesn't make sense for C to be an animal array, a dog array, or a cat&lt;br /&gt;array. Therefore, IMHO it doesn't really make sense to allow concatenating&lt;br /&gt;A and B. &lt;/greg9504@removeforspam.hotmail.com&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;&lt;span style="font-size:78%;"&gt;--&lt;br /&gt;Steve Lord&lt;br /&gt;slord@mathworks.com&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;IMHO, the only reasonable answer to Steve's question "What class should C = [A; B] be?" is an animal array, not just for consistency with the documentation as described above, but for some more extensive reasons I'll go into below.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Let me first discuss the issue Steve raised, that for C to be an animal array, the pieces that A and B have that aren't in the animal class would have to be removed. First of all, in some cases there might not be any extra bits at all. For example, the Matlab documentation suggests using inheritance as a method of class aliasing:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;pre&gt;&lt;blockquote style="color: rgb(153, 153, 153);"&gt;&lt;span style="font-size:78%;"&gt;classdef &lt;tt&gt;&lt;i&gt;newclassname&lt;/i&gt;&lt;/tt&gt; &lt; &lt;tt&gt;&lt;i&gt;oldclassname&lt;/i&gt;&lt;/tt&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);font-size:78%;" &gt;end&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt;   &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Even though there aren't any additional properties or methods, we still can't create a mixed array: &lt;/span&gt;&lt;span style=";font-family:Courier New,monospace;font-size:85%;"  &gt;[oldclassname() newclassname()] &lt;/span&gt;&lt;span style="font-size:85%;"&gt; raises the same error we saw earlier.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Obviously, in most cases derived classes will have additional properties and methods. Fortunately, there seems to be a context in which these "extra bits" are handled intuitively, robustly, and quietly. Consider an array of dynamicprops-derived objects:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt;&lt;blockquote&gt; &lt;span style=";font-family:courier new;font-size:78%;"  &gt;classdef MyObj &lt; defaultprop =" 1"&gt;&gt; obj1 = MyObj();&lt;br /&gt;&gt;&gt; obj2 = MyObj();&lt;br /&gt;&gt;&gt; obj1.addprop('ExtraProp1'); obj1.ExtraProp1 = 100;&lt;br /&gt;&gt;&gt; obj2.addprop('ExtraProp1'); obj2.ExtraProp1 = 200;&lt;br /&gt;&gt;&gt; obj2.addprop('ExtraProp2'); obj2.ExtraProp2 = 300;&lt;br /&gt;&gt;&gt; objs = [obj1 obj2];&lt;br /&gt;&gt;&gt; [objs.DefaultProp]&lt;br /&gt;&lt;br /&gt; ans = 1 1&lt;br /&gt;&lt;br /&gt;&gt;&gt; [objs.ExtraProp1]&lt;br /&gt;&lt;br /&gt; ans = 100 200&lt;br /&gt;&lt;br /&gt;&gt;&gt; [objs.ExtraProp2]&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;??? No appropriate method, property, or field ExtraProp2 for class Engineer.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt; objs(2).ExtraProp2&lt;br /&gt;&lt;br /&gt; ans = 300&lt;/span&gt;&lt;/blockquote&gt;&lt;span style=";font-family:courier new;font-size:78%;"  &gt; &lt;/span&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;br /&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;This is &lt;b&gt;exactly&lt;/b&gt;&lt;/span&gt;&lt;span style="font-weight: normal;font-size:85%;" &gt; how arrays of mixed class/subclass objects should behave. Properties which exist for all objects in the array are accessible, and properties which exist for only some subset of the array are inaccessible, unless that subset is explicitly indexed.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in; font-weight: normal;"&gt;&lt;span style="font-size:85%;"&gt;Now that I've established that arrays &lt;span style="font-weight: bold;"&gt;could&lt;/span&gt; contain mixed base/subclasses, let me explain why they &lt;span style="font-weight: bold;"&gt;should&lt;/span&gt;, beyond simple consistency with the documentation.&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;1) Ease of use&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Cell arrays of objects are much more awkward and less intuitive to work with than regular arrays. Consider the following examples:&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 0);font-size:85%;" &gt;&lt;tt&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;&lt;span style="font-family:Courier New,monospace;"&gt;&lt;span style="font-style: normal;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;%Desired behavior - easy to read and write &lt;/span&gt;&lt;br /&gt;employees = [Engineer(), SalesPerson()];&lt;br /&gt;salaries = [employees.Salary];&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;%Current usage requires cell arrays, which are harder to read and write with &lt;/span&gt;&lt;br /&gt;employees = {Engineer(), SalesPerson()};&lt;br /&gt;salaries = cellfun(@(e) (e.Salary), employees);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;%Even uglier: &lt;/span&gt;&lt;br /&gt;employees = {Engineer(), SalesPerson()};&lt;br /&gt;nEmployees = length(employees);&lt;br /&gt;salaries = zeros(1, nEmpoyees);&lt;br /&gt;for i = 1:nEmployees&lt;br /&gt;  salaries(i) = employees{i}.Salary;&lt;br /&gt;end &lt;/span&gt; &lt;/blockquote&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		A:link { so-language: zxx } 	--&gt; 	&lt;/style&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;2) The current interface discourages proper OOP principles&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in; font-weight: normal;"&gt;&lt;span style="font-size:85%;"&gt;Imagine you have a large suite of functions for handling some custom class Engineer. If you don't sufficiently plan ahead, you might not consider the possibility of subclassing Engineer. Down the road, doing so would require the &lt;b&gt;extensive and frustrating re-writing of every line of code that operated on arrays of Engineers. &lt;/b&gt;This could lead to an inertial response to proposed extensions and &lt;b&gt;defeats the entire purpose of object-oriented programming principles.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;3) The current interface encourages bad OOP principles.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in; font-weight: normal;"&gt;&lt;span style="font-size:85%;"&gt;Let's say there's been a proposal to subclass Engineer to TestEngineer. One potential way to avoid extensive rewriting of code would be to add an ExtraStuff property to the base class, and create a new class called TestEngineerExtraStuff. An instance of this class could then be stored in the ExtraStuff field of every Engineer instance that we would have otherwise subclassed to TestEngineer. I hope I don't need to explain why this is a horrible design decision, and yet the current OOP interface in Matlab &lt;b&gt;encourages this behavior.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;4) The community wants it!&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0in; font-weight: normal;"&gt;&lt;span style="font-size:85%;"&gt;Searching the newsgroup for "object array subclass" returns multiple cases (&lt;a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/239226#631784"&gt;here&lt;/a&gt;, &lt;a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/171821#440432"&gt;here&lt;/a&gt;, and &lt;a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/170236#435366"&gt;here&lt;/a&gt;), as well as the aforementioned technical solution, where Matlab users expect their code to behave as I am promoting, and are told to use cell arrays instead. I imagine there's even more cases where users found work-arounds on their own without posting about it on the newsgroup.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;The problem of method call dispatching&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;	&lt;/p&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;The biggest problem with my proposal relates to what should be done with method calls to mixed class/subclass arrays, like employees.giveRaise(10). This is a bit confusing due to the difference in how Matlab treats property assignment/referencing and method calls.&lt;br /&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Property references on arrays of objects returns a comma separated list, that is: MyObjArray.MyProp is equivalent to &lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyObjArray(1).MyProp, &lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyObjArray(2).MyProp, &lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyObjArray(3).MyProp,... whereas method calls act on the entire array, so MyObjArray.MyMethod() is &lt;span style="font-weight: bold;"&gt;NOT&lt;/span&gt; equivalent to &lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyObjArray(1).&lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyMethod()&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, &lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyObjArray(2).&lt;/span&gt;&lt;span style="font-size:85%;"&gt;MyMethod()&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, ...&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt;   &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;If this was consistent, there wouldn't be any problem for methods calls -- each instance in the array would call its own methods by standard method scoping rules. As is, there are multiple ways of handling method dispatching, each with its own advantages and disadvantages:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Find the first common ancestor in 	which the method is implemented. Thus 	employees.giveRaise(10) would call Employee.giveRaise(employees, 	10), regardless of whether or not SalesPerson implemented its own 	giveRaise method. An error is raised if no such method is 	found.&lt;br /&gt;&lt;/span&gt; 	&lt;/p&gt; 	&lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Call each instance's method 	independently no matter what, as in obj(1).method(), 	obj(2).method()... This is probably the simplest approach, although it would be pretty frustrating for classes derived from numerical bases used for computation.&lt;br /&gt;&lt;/span&gt; 	&lt;/p&gt; 	&lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Break up array into classes by 	each unique implementation, and dispatch each sub-array. Thus given 	&lt;br /&gt;&lt;br /&gt;	employees = [Employee, Engineer, Engineer, SalesPerson, 	Engineer];&lt;br /&gt;&lt;br /&gt;employees.giveRaise(10) would call, in order:&lt;br /&gt;&lt;br /&gt;	    	Employee.giveRaise(employees(1), 	10)&lt;br /&gt;	Engineer.giveRaise(employees([2, 3, 5]), 	10)&lt;br /&gt;	SalesPerson.giveRaise(employees(4), 10)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-size:85%;"&gt;Personally, I'd be fine with any of these options, although the third one is probably overly complicated and difficult to debug. The first implementation is probably the most intuitive and useful choice.&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;meta equiv="CONTENT-TYPE" content="text/html; charset=utf-8"&gt;&lt;title&gt;&lt;/title&gt;&lt;meta name="GENERATOR" content="OpenOffice.org 3.0  (Win32)"&gt;&lt;style type="text/css"&gt; 	&lt;!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 	--&gt; 	&lt;/style&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in; font-weight: bold;"&gt;&lt;span style="font-size:100%;"&gt;Implementation&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;  &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;Probably the best way to implement what I'm pitching here would be for The MathWorks to provide some abstract class SubclassConcatable. Custom classes would subclass this, and then work as I'm described. Custom classes that don't subclass  SubclassConcatable would behave as is currently standard, which would maintain backwards compatibility.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;What do you think?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;I've done my best to make a pretty comprehensive case here, but I've probably missed something obvious. Let me know!&lt;br /&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3128290857071255389-4322366404542662603?l=repmat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://repmat.blogspot.com/feeds/4322366404542662603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://repmat.blogspot.com/2009/03/matlab-oop-oversight.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default/4322366404542662603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3128290857071255389/posts/default/4322366404542662603'/><link rel='alternate' type='text/html' href='http://repmat.blogspot.com/2009/03/matlab-oop-oversight.html' title='Matlab OOP Oversight '/><author><name>dg</name><uri>http://www.blogger.com/profile/14091083649493610193</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry></feed>
