Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



object.vector(100) = 1
Posted:
Jan 22, 2013 5:33 PM


.... does this always reallocate/copy the complete vector although it is preallocated?
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 testcode



