[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Another request for classdef test in Matlab
From: |
Ben Abbott |
Subject: |
Re: Another request for classdef test in Matlab |
Date: |
Fri, 04 Jan 2013 18:38:02 -0500 |
On Jan 4, 2013, at 6:03 PM, Michael Goffioul wrote:
> On Fri, Jan 4, 2013 at 5:57 PM, Ben Abbott <address@hidden> wrote:
>
> On Jan 4, 2013, at 5:44 PM, Michael Goffioul wrote:
>
> > On Fri, Jan 4, 2013 at 5:41 PM, Ben Abbott <address@hidden> wrote:
> >
> > On Jan 4, 2013, at 5:26 PM, Michael Goffioul wrote:
> >
> > > Can anyone test the following in Matlab.
> > >
> > > Have a class defined in ClassA.m as:
> > >
> > > classdef ClassA < handle
> > > properties
> > > x = 1;
> > > end
> > > methods
> > > function obj = ClassA (x)
> > > obj.x = x;
> > > end
> > > end
> >
> > I had a few minutes to get back to this today. Looks like I'm helping with
> > the easy parts ;-)
> >
> > You missed an "end"
> >
> > classdef ClassA < handle
> > properties
> > x = 1;
> > end
> > methods
> > function obj = ClassA (x)
> > obj.x = x;
> > end
> > end
> > end
> >
> >
> > > At the prompt, execute:
> > >
> > > a(2,2) = ClassA (2)
> >
> > a(2,2) = ClassA (2)
> > Error using ClassA (line 7)
> > Not enough input arguments.
> >
> > Of course, use this instead:
> >
> > classdef ClassA < handle
> > properties
> > x = 1;
> > end
> > methods
> > function obj = ClassA (x)
> > if nargin > 0
> > obj.x = x;
> > end
> > end
> > end
> > end
> >
> > Michael.
>
> Ok. That behaves like a structure, and returns a cs-list.
>
> clear all
> a(2,2) = ClassA (2)
>
> a =
>
> 2x2 ClassA handle
>
> Properties:
> x
>
> Methods, Events, Superclasses
>
> a.x
>
> ans =
>
> 1
>
>
> ans =
>
> 1
>
>
> ans =
>
> 1
>
>
> ans =
>
> 2
>
>
> What about the rest of the commands?
>
opps. They are below.
>> a(1,1).x, a(2,2).x
ans =
1
ans =
2
>> a(1,1) == a(1,2)
ans =
0
>> h = a(1,1)
h =
ClassA handle
Properties:
x: 1
Methods, Events, Superclasses
>> h.x = 3
h =
ClassA handle
Properties:
x: 3
Methods, Events, Superclasses
>> a(1,1).x, h.x
ans =
3
ans =
3
Ben
- Another request for classdef test in Matlab, Michael Goffioul, 2013/01/04
- Re: Another request for classdef test in Matlab, Ben Abbott, 2013/01/04
- Re: Another request for classdef test in Matlab, Michael Goffioul, 2013/01/04
- Re: Another request for classdef test in Matlab, Michael D. Godfrey, 2013/01/04
- Re: Another request for classdef test in Matlab, Ben Abbott, 2013/01/04
- Re: Another request for classdef test in Matlab, Michael Goffioul, 2013/01/04
- Re: Another request for classdef test in Matlab, Philip Nienhuis, 2013/01/04
- Re: Another request for classdef test in Matlab,
Ben Abbott <=
- Re: Another request for classdef test in Matlab, Ben Abbott, 2013/01/04
- Re: Another request for classdef test in Matlab, Philip Nienhuis, 2013/01/04
- Re: Another request for classdef test in Matlab, Michael Goffioul, 2013/01/04
- Re: Another request for classdef test in Matlab, Michael Goffioul, 2013/01/04
- Re: Another request for classdef test in Matlab, Michael D. Godfrey, 2013/01/04
- Re: Another request for classdef test in Matlab, Philip Nienhuis, 2013/01/05
- Re: Another request for classdef test in Matlab, Michael Goffioul, 2013/01/05
- Re: Another request for classdef test in Matlab, Michael D. Godfrey, 2013/01/05
- Re: Another request for classdef test in Matlab, Philip Nienhuis, 2013/01/05
- Re: Another request for classdef test in Matlab, Michael Goffioul, 2013/01/05