% % a couple of test cases to show how IPF works % % %% EXAMPLE 1: From http://en.wikipedia.org/wiki/Iterative_proportional_fitting %% note that T satisfies the row and col sum constraints, so S should remain unchanged T = [[43 9]; [44 4]]; R = [52; 48]; C = [87 13]; [S, iterations, errors] = ipf(T, R, C) %% EXAMPLE 2: add some noise to T before performing IPF T = T + randn(size(T)); [S, iterations, errors] = ipf(T, R, C) %% note that S comes out close to the old value of T, though not quite the same, %% but that the row and col sums are now correct