MATLAB: Given Two Matrices, Match each element with the element in other matrix, export to ASCII File

matrix array

I have two matrices that are both 50X50. What I need to do is match each element in the first matrix with the element in the second matrix, and write them to an ASCII file.
For example, say I have two 2X2 matrices
A = [1 2 ; 3 4]
B = [5 6 ; 7 8]
The output in an ASCII file should be :
1 5
2 7
3 7
4 8
Except, I need to do this for much larger matrices. Any ideas? Thanks.

Best Answer

A = [1 2 ; 3 4]
B = [5 6 ; 7 8]
a=A';
b=B';
out=[a(:) b(:)]
dlmwrite('file.txt',out)
Related Question