Cross - Table with frequency of categories matlab
<p>I have two matrices A and B that contain integer values assigned to a category. I want to create a table <code>P</code> where <code>P(i,j)= p(A=i&amp;B=j)</code>: Meaning that <code>P(1,1)</code> holds the probability of an element of A to be category 1 and  the same element of <code>B</code> to be category 1. Also to be clear, if you sum <code>P</code> across rows you find the frequency of categories for A matrix and if you sum P across columns you find frequency of categories for B matrix.</p>

<p>It is easy to execute with for-loops, but i compare huge matrices (maps with land use categories) and it is very slow as should be expected with every for-loop implementation.</p>

<p>Is there  a built in function in matlab or a simpler way to do this? I searched a lot but could not find something that works with matrices. Thanks in advance!</p>