function assigns=structvars(S,RHS)


if nargin<2, RHS=true; end
    
fields=fieldnames(S);

sname=inputname(1);
if isempty(sname), sname='S'; end


if RHS
    
 assigns= cellfun(@(f) [f ' = ' sname '.' f ';'],fields,'uniformoutput',0);
 
else %LHS
    
 assigns= cellfun(@(f) [ sname '.' f ' = ' f ';'],fields,'uniformoutput',0);
    
end

assigns=strvcat(assigns);