function [subExpr exprO tempVars]=subsTrigo(expr)

for k=1:length(expr)
    exprCell{k} = char(expr(k));
end


[subExpr exprOut tempVars]=subsOne(exprCell, expr);


for k=1:length(exprOut)
    exprO(k) = sym(exprOut{k});
end

% subExpr=[];
% exprOut=[];
% 
% for k=1:length(expr)
%     [subExprStr exprStr] = subsOne(expr(k));
%     add=1;
%     for n=1:length(subExpr)
%         if strcmp()==0, add=0; end
%     end
% end



function [subExpr exprCell tempVars]=subsOne(exprCell, expr)

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

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

subExpr={};
tempVars={};

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