The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Value classes - do you use them? also syntax questions
Replies: 4   Last Post: May 22, 2013 4:32 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Value classes - do you use them? also syntax questions
Posted: May 21, 2013 5:50 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Eric Sampson" <> wrote in message
> I posted the below on Answers but got no responses, perhaps the newsgroup
> is a better forum to discuss this :)
> ---------
> So I can't really recall ever creating a value class, all mine seem to be
> handle classes. Is that the same as your experience? Unless I'm completely
> missing something, using value classes seems to be a bit ungainly, because
> you always have to do two steps like this:
> foo = MyValueClass(5); % sets a property 'val'
> foo = foo.double();
> plot(foo.val);

Why does the DOUBLE method of the MyValueClass return an object instead of a
double array?

> With a handle class, I'd just do this:
> foo = MyHandleClass(5);
> plot(foo.double()); % double returns the new obj.val directly.
> Am I completely out to lunch with this understanding of value classes?

I suggest you read through this if you haven't already.

My mental model: if I want to use the object like a MATLAB array, I make it
a value.

A = [1 2 3; 4 5 6];
C = A;
b = sin(A);

If the object is a "pointer" or refers to something with physical meaning
(where it doesn't make sense to "copy" it by doing assignment) I make it a

fid = myFileObject('c:\temp\temp.txt'); % There is only one temp.txt file in
h = myCompositeGraphicsObject; % h is associated with an object on screen
h2 = h % h2 and h both refer to the same object; there's no copying being
done here

> As an aside, sometimes it seems like it would be nice to have the above
> syntax of a handle class, but be able to make independent copies of a
> given object like a value class... Anyone else think so?

That's what matlab.mixin.Copyable is for.

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.