I assume you want to find the output size after 2D convolution with an argument as ‘valid’.
In the case where
S = conv2(S1, S2, 'valid')
The output size o = (i-k) + 1
Where i is the size of the input matrix. k is the kernel size. (Here i corresponds to S1 and k to S2)
In this case, S1 is of size (X1, Y1) and S2 is of size (X2, Y2)
Hence output size 0 = (X1 - X2 + 1) in the x-direction and similarly
output along the y-direction is (Y1-Y2 + 1)
That is, the output size will be (X1-X2+1, Y1-Y2+1).