Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Preallocation help needed
Replies: 0

 Amadeus Posts: 9 Registered: 10/8/12
Preallocation help needed
Posted: Dec 10, 2012 3:39 PM

Hello,

I could not find out how to properly do the preallocation for the following situation. Could you please give me a hand?

Regards

Size of tracks' changes every loop, so I want to do preallocation for it but could not figure out how. (Size of tracks(1,i).nPoints remains same. Only tracks(1,i).matrix changes, 1?i?max_n_trks)

%% Interpolation

interp=1;

for param=1:interp

for k=1:max_n_trks % maximum number of tracks

vector = tracks(1,k).matrix;
len = tracks(1,k).nPoints;

for i=len:-1:1

vector(2*i-1,:,:)=vector(i,:,:);

end

tracks(1,k).nPoints = (tracks(1,k).nPoints*2)-1;
len = tracks(1,k).nPoints;

for i=1:2:len-1

vector(i+1,:,:) = (vector(i,:,:) + vector(i+2,:,:))/2;

end

tracks(1,k).matrix = vector;

end

end