function [sol]=ompsol(A,b,L)
%solves for x in Ax=b, with number of non-zero elements of the vector b is
%minimized
temp=A;
vect=[];
res=b;
sol=zeros(size(A,2),1);
M=ones(size(A,1),size(A,2));
pos=[];
for iteration=1:1:L
[p,q]=max(temp'*res);
vect=[vect A(:,q)];
s=pinv(vect)*b;
res=b-vect*s;
M(:,q)=zeros(size(A,1),1);
temp=temp.*M;
pos=[pos q];
sol(pos)=s;
if(sum(res.^2)<0.01)
break
end
end
