matching two files contents using matlab and outputted the result as a matrix -
i new matlab. need solve problem. tried implement several codes unfortunately not able find solution.
i have file , need compare each row remaining , output results matrix contains 1s of matched items , 0s otherwise. if 2 rows overlapped using 2 , 3 columns shown in example,the matrix has 1 . example have following rows in file.
1 x 10 20 a
2 y 15 20 t
3 c 25 40 a
the output should be:
1 2 3 1 0 1 0 2 1 0 0 3 0 0 0
really appreciate help.
thanks
that should it
% open file fh = fopen('test.txt'); % read data (adjust 10000 if necessary) dat = textscan(fh, '%d %s %d %d %s', 10000); % extract high , low values hi = dat{4}; lo = dat{3}; % create grid [ hig, log ] = meshgrid(hi, lo'); % compare high, low overs = ~(log >= hig); % check both ends & 0 out diagonal res = overs & overs' & ~logical(eye(length(hi))); % close file fclose(fh); res
Comments
Post a Comment