Path: news.mathworks.com!not-for-mail
From: "Rich Ellis" <rich@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Array of class objects?
Date: Tue, 13 Oct 2009 17:09:24 -0400
Organization: The MathWorks, Inc.
Lines: 51
Message-ID: <hb2qa8$f9m$1@fred.mathworks.com>
References: <hb2i5a$hp4$1@fred.mathworks.com>
Reply-To: "Rich Ellis" <rich@mathworks.com>
NNTP-Posting-Host: ellisr.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1255468168 15670 172.31.46.117 (13 Oct 2009 21:09:28 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 Oct 2009 21:09:28 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:577079


I think you want this syntax:

test(1) = {mypoint}


"David Doria" <daviddoria@gmail.com> wrote in message 
news:hb2i5a$hp4$1@fred.mathworks.com...
> If I have a class:
>
> classdef DataPoint
>
>    properties
>        Point
>        ClassId
>    end
>
>    methods
>        function DP = DataPoint(Point, ClassId)
>            DP.Point = Point;
>            DP.ClassId = ClassId;
>        end
>        function display(DP)
>            disp(['DataPoint: x=', num2str(DP.Point(1)), ' y=', 
> num2str(DP.Point(2))])
>        end
>
>    end
>
> end
>
> And I want a bunch of DataPoint's in an array, I thought I would make a 
> cell array and store them there:
>
> mypoint = DataPoint([0 2], 1)
> test = cell(5,1);
> test(1) = mypoint
>
>
> However I get this error:
> ??? The following error occurred converting from DataPoint to cell:
> Error using ==> cell
> Conversion to cell from DataPoint is not possible.
>
> How should I make an array of DataPoint's?
>
> Thanks,
>
> Dave
>