0

我希望有人可以帮助我,如何实现这一目标。我必须包含数据列表的文件,我正在尝试计算两个列表之间可能的排列并将它们保存到一个新文件中。我意识到我的输出文件非常大(超过 30 Gb)。我想知道如何仅在符合特定标准的数据之间进行排列。F.eks 如果:

数据 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 回答