function [subExpr expr tempVars]=subsSinCos(expr)

str = findsym(sym(expr));
eval(['vars={''' strrep(str,', ',''', ''') '''};']);

toSub={'sin','cos'};

subExpr={};
tempVars={};

for k=1:length(toSub)
    while ~isempty(strfind(expr,toSub{k}))
        I=strfind(expr,toSub{k});
        I=I(1);
        if expr(I+length(toSub{k}))=='('
            parLev=0;
            Ii=I+length(toSub{k});
            %cont=1;
            while 1
                if expr(Ii)=='(', parLev=parLev+1; end
                if expr(Ii)==')', parLev=parLev-1; end
                if parLev==0, Iend=Ii; break; end
                Ii=Ii+1;
            end
            tempVars{length(tempVars)+1} = genvarname('temp', [vars, tempVars]);
            subExpr{length(subExpr)+1} = expr(I:Iend);
            expr=strrep(expr,subExpr{end},tempVars{end});
        end
    end
end