0

これを達成する方法、誰かが私を助けてくれることを願っています。データのリストを含むファイルが必要です.2つのリスト間の可能な順列を計算し、それらを新しいファイルに保存しようとしています. 出力ファイルが非常に大きい (30 Gb 以上) ことに気付きました。特定の条件を満たすデータのみを並べ替える方法を知りたいです。F.eks if :

データ 1: VHxBxVVxPx255x98x
データ 2: VHxBxVVxPx255x98x

data1 の char(6 と 7) = data2 の char(6 と 7) の場合にのみ並べ替えます。

これまでの私のコード:

    fid = fopen( 'file1.txt' );
    cac = textscan( fid, '%20s' );
    fclose( fid );
    num = cac{1};
    fid = fopen( 'file2.txt' );
    cac = textscan( fid, '%20s' );
    fclose( fid );
    str = cac{1};
    fid = fopen( 'file3.txt', 'w' );
    for ii = 1 : length( num )
        for jj = 1 : length( str )
            fprintf( fid, '%1s - %1s\n', num{ii}, str{jj} );
        end
    end   
    fclose( fid );    
4

2 に答える 2

0

@ Kostya ...残念ながらあなたのコードを動作させることができませんでした。しかし、私は自分のコードを次のように変更して動作させることができました:

fid = fopen( 'file1.txt' ); cac = textscan( fid, '%20s' ); num = cac{1}; fclose( fid );
fid = fopen( 'file2.txt' ); cac = textscan( fid, '%20s' ); str = cac{1}; fclose( fid );

fid = fopen( 'file3.txt', 'w' );

for i = 1 : length(num)
  for j = 1 : length(str)
       compare = strcmp(num{i}(1:2),str{j}(1:2));
       if compare == 0
           fprintf( fid, '%1s%1s\n', num{i}, str{j} );
       end
  end
end

fclose( fid );
于 2014-11-11T16:33:37.380 に答える
0

このようなものを使用できます

clear all;
fid = fopen( 'file1.txt' ); cac = textscan( fid, '%20s' ); num = cac{1}; fclose( fid );
fid = fopen( 'file2.txt' ); cac = textscan( fid, '%20s' ); str = cac{1}; fclose( fid );

fid = fopen( 'file3.txt', 'w' );

for inum = 1 : size(num,1)
    inxmCells = cellfun(@(x) strcmp(x(6:7), num{inum}(6:7)), str,'UniformOutput', false); %[0,1] index of (non)matching cells
    mCells = str(logical(cell2mat(inxmCells)));
    for j = 1 : length( mCells )
        fprintf( fid, '%1s - %1s\n', num{inum}, mCells{j} );
    end
end
fclose( fid );
于 2014-11-11T00:13:57.300 に答える