0

i hope someone can help me, how to achieve this. I have to files with list of data, i am trying to calculate possible permutations between the two lists and save them to a new file. i realized that my output file is very big ( more than 30 Gb ). i would like to know how to make permutation only between the data that meets specific criteria. F.eks if :

Data 1: VHxBxVVxPx255x98x
Data 2: VHxBxVVxPx255x98x

only permutate if char(6 and 7) from data1 = char(6 and 7) from data2.

my code so far :

    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 );    

2 Answers2

0

You can use something like this

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 );
Kostya
  • 1,552
  • 1
  • 10
  • 16
  • Thanks for the answer, but it doesnt seem to work, with you code it seems that i am getting permutations of Data1 and Data2 – mounim korchi Nov 11 '14 at 08:45
  • @mounimkorchi Yes, for a larger list of strings it requires an extra pairwise string comparison. Let me update the answer in a min – Kostya Nov 11 '14 at 13:13
  • it is not really working. it seems that it is only taking the cells that does not match and flip them to get this output ( i will write in a new comment ) – mounim korchi Nov 11 '14 at 16:31
  • @mounimkorchi Sorry, was typing too quickly and overlooked a difference between cell and logical. Just corrected the code :) – Kostya Nov 11 '14 at 17:01
  • i am sorry, but i still cannot get your code to work, still almost get the same output: ", - V" can you also please explain why shifting the string vertically ? – mounim korchi Nov 11 '14 at 17:19
  • Oh i see, sorry, misunderstood your question, i thought you're looking for symbol-wise permutations. One sec... – Kostya Nov 11 '14 at 17:24
0

@ Kostya ... i could unfortunetly not get your code to work. but i managed to get it work changing my code as so :

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 );