Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Loop through large number of files and access arrays outside the loop ?

1 回表示 (過去 30 日間)
dipak sanap
dipak sanap 2015 年 11 月 23 日
閉鎖済み: Walter Roberson 2015 年 11 月 23 日
for i = 1:50000
f = fopen(sprintf('F%d', i), 'r'); %File names are F1, F2 and son on.
X{i} = fscanf(f, '%d %d %f %d',[4, inf]); % Matlab nag about prellocating memory.
X{i} = X{i}';
A{i} = X(:,1:3); %Want to access only three columns of X{i} and make it A(i) and access it outside loop.
fclose(f);
end
U = union(A(:,1:2),,'rows'); %Take union of first two colums of all A(i)
for j = 1:50000
Ua(j) = setdiff(U(:,1:2), A(:,1:2),'rows');%Again access A(i) from previous loop
Ua_z(j) = [Ua(j) zeros(size(Ua,1),1)]; % Add zero column to Ua(j)
AU(j) = [A(i) ; Ua_z(j)]; % Vertically concatenate A(i) and Ua_z(j)
AU_sorted(j) = sortrows(AU); %Sort rows of AU(j)
end
C = [U(:,1:2), AU_sorted(:,3)]; % Horizontally concatenate U and AU_sorted(j)
  2 件のコメント
Thorsten
Thorsten 2015 年 11 月 23 日
編集済み: Thorsten 2015 年 11 月 23 日
So what's your question?

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by