MATLAB: How to compare one column of one matrix with all columms of other matrix one by one? matlab 2014b

columnscomparisiionmatrixvector

suppose N is 7×8 matrix, M is 7×8 matrix. both are different i want N(:,1)-M(:,1);N(:,1)-M(:,2);N(:,1)-M(:,3)………..N(:,2)-M(:,1);N(:,2)-M(:,2) and so on. how to do that? please help me. I am using matlab version 2014b.

Best Answer

R2016b or later:
N - permute(M, [1 3 2])
Pre-R2016b:
bsxfun(@minus, N, permute(M, [1 3 2]))
will give you a 7x8x8 matrix where each (:, i, j) is N(:, i) - M(:, j)