Intersection of orthonormal basis of two subspaces I want to ask how can I form a subspace which is an intersection of the orthonormal basis of two another subspaces and find its dimension in Matlab?
Thank you in advance,
Maya
 A: I had the same question and I have wasted the whole afternoon to seek a answer in internet. There is a function in MuPAD but I don't know how to call it in matlab.
The following link is a function in Matlab. 
The code there is a little confusing for me so finally I decide to write one by myself. Surprisingly, I find actually it is not so hard as I have imagined. The whole function is just as follow, hope that it can help someone seeking the same answer 
function [I]=IntersectionS(M1,M2)
%find the common vectors of two subspace col(M1) and col(M2)
%INPUT: two matrices M1 and M2
%OUTPUT: a basis for intersection of col(M1) and col(M2)
%---------------------------------------------------
%M1*x=M2*y=z
%col(I)=span(z1,z2,...)
%----------------------------------------------------
%example:M1=[1 0; 1 1;  0 3; -1 1];M2=[0 1; -1 2; -2 2; 1 -2];[I]=IntersectionS(M1,M2);
%by ZHANG zhelai 2014.9.29  zhangzhelai@163.com
O1=orth(M1);
O2=orth(M2);
temp=O1*(O1'*O2)-O2;
if norm(temp,'fro') < 10^-6
    I=O2;
else
    yspan=null(temp);
    I=orth(O2*yspan);
end

