Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

Topic: object.vector(100) = 1
Replies: 2   Last Post: Jan 23, 2013 5:51 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: 17,944
Registered: 12/7/04
Re: object.vector(100) = 1
Posted: Jan 23, 2013 10:22 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"Peter Mairhofer" <63832452@gmx.net> wrote in message
news:kdn44k$vib$1@news.albasani.net...
> ... does this always re-allocate/copy the complete vector although it is
> pre-allocated?
>
> classdef SampledSignal
> properties (GetAccess = 'public', SetAccess = 'public')
> data;
> end
>
> methods
> function this = set.data(this, vector)
> [...]
> this.data = vector(:);
> end
> end
>
> methods
> function this = SampledSignal(N)
> [...]
> this.data = zeros(N, 1);
> end
> end
>
> x = SampledSignal;
> for n=1:N
> x.data(n) = func(n);
> end
>
> takes forever;


It calls your set.data method N times. If you had a get.data method as well,
it too would be called N times. If N is large, that could take a while.

http://www.mathworks.com/help/matlab/matlab_oop/property-access-methods.html#brh8ht7

> x = SampledSignal;
> data = x.data;
> for n=1:N
> data(n) = func(n);
> end
> x.data = data;
>
> takes "only" 30 seconds on my old machine.
> Why?


This calls your set.data method 1 time on the last line and a get.data
method (if you have one) 1 time on the second line.

How large a value of N are you using? How long does 1 call to set.data take?
If you let it run about 30 seconds plus (N-1)*(duration of a set.data call)
[for a smaller value of N] does the first code complete its execution?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.