2

ラボの作業から処理する必要がある大量のデータがあります。次元 7 x w の信号行列を含む大量の .mat ファイルがあります。行列のサイズを 7 x N に変更する必要があり、残りの分析を容易にするために、w は N よりも大きくまたは小さくする必要があります (N を超えるデータは気にしないでください)。これをどのように機能させたいかという疑似コードがありますが、実装方法がわかりません。どんな助けでも大歓迎です!

すべてのデータのフォルダー構造:

メインフォルダー

Alpha 1
    1111.mat
    1321.mat
Alpha 2
    1010.mat
    1234.mat
    1109.mat
    933.mat
Alpha 3
    1223.mat

疑似コード:

    Master_matrix = []
    For all n *.mat
        Load n'th *.mat from alpha 1
        If w > N
            Resize matrix down to N
        Else
            Zero pad to N
        End if
    Master_matrix = master_matrix .+ new resized matrix
    End for

rest of my code...
4

1 に答える 1

2

まず、ファイル リストを生成する必要があります。私はそのための独自の関数を持っていますが、たとえば、ファイルのリストを生成するための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

于 2010-11-11T18:24:03.217 に答える