Info

This question is closed. Reopen it to edit or answer.

Prellocate memory to unknown size array ?

1 view (last 30 days)
dipak sanap
dipak sanap on 24 Nov 2015
Closed: Walter Roberson on 24 Nov 2015
numfiles = 3;
A = [];
for i = 1:numfiles
f = fopen(sprintf('F%d', i), 'r');
D = fscanf(f, '%d %d %f',[3, inf]); % Prellocate memory.
D = D';
P(i).element = D;
A = [A; D]; %Prellocate memory
fclose(f);
end
B = zeros(size(A(:,1:2)));
U = setdiff(A(:,1:2),B,'rows');
C = [];
for j = 1:numfiles
Ua(j).ele = setdiff(U(:,1:2), P(j).element(:,1:2),'rows');%Prellocate memory
Ua_z(j).ele = [Ua(j).ele , zeros(size(Ua(j).ele,1),1)]; % Prellocate memory
AU(j).ele = [P(j).element ; Ua_z(j).ele]; % Prellocate memory
AU_sorted(j).ele = sortrows(AU(j).ele); %Prellocate memory
C = [C, AU_sorted(j).ele(:,3)];
end
CU = [U(:,1:2), C]; % Horizontally concatenate U and AU_sorted(j)

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!