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 ]
Peter Mairhofer

Posts: 25
Registered: 8/18/10
object.vector(100) = 1
Posted: Jan 22, 2013 5:33 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

.... 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;

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 makes all a little bit meaningless.

Thanks
Peter

PS: I know vector operations are faster, this is only unoptimized test-code



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.