まず、ファイル リストを生成する必要があります。私はそのための独自の関数を持っていますが、たとえば、ファイルのリストを生成するためのGETFILELISTや優れたインタラクティブなUIPICKFILESがあります。
ファイル リストを取得したら (ファイル名を含むセル配列であると仮定します)、次の操作を実行できます。
nFiles = length(fileList);
Master_matrix = zeros(7,N);
for iFile = 1:nFiles
%# if all files contain a variable of the same name,
%# you can simplify the loading by not assigning an output
%# in the load command, and call the file by
%# its variable name (i.e. replace 'loadedData')
tmp = load(fileList{iFile});
fn = fieldnames(tmp);
loadedData = tmp.(fn{1});
%# find size
w = size(loadedData,2);
if w>=N
Master_matrix = Master_matrix + loadedData(:,1:N);
else
%# only adding to the first few columns is the same as zero-padding
Master_matrix(:,1:w) = Master_matrix(:,1:w) = loadedData;
end
end
注: 実際にデータを合計するのではなく、単にマスター配列に格納する場合はMaster_matrix、7 x N x nFiles 配列にすることができます。ここで、n 番目の平面Master_matrixはのコンテンツです。 n 番目のファイル。この場合、次のように初期化Master_matrixします
Master_matrix = zeros(7,N,nFiles);
そして、if節を次のように書きます
if w>=N
Master_matrix(:,:,iFile) = Master_matrix(:,:,iFile) + loadedData(:,1:N);
else
%# only adding to the first few columns is the same as zero-padding
Master_matrix(:,1:w,iFile) = Master_matrix(:,1:w,iFile) = loadedData;
end
また、ゼロが後続の統計に影響を与えないように、の代わりにMaster_matrixasを初期化したい場合があることに注意してください(それがデータでやりたいことである場合)。NaNzeros