function stackMath(x)

if nargin == 0
   x = {3 4 '*' 2 5 '*' '+'};
end

stack = {};
for ii = 1:length(x)
   if isnumeric(x{ii})
      fprintf('%d ', x{ii})
      stack = push(x{ii}, stack);
   elseif ismember(x{ii}, '+*-/')
      fprintf('%c ', x{ii})
      [a stack] = pop(stack);
      [b stack] = pop(stack);
      c = eval(sprintf('%d %c %d', a, x{ii}, b));
      stack = push(c, stack);
   end
end

[v stack] = pop(stack);
fprintf('= %d\n', v)
end

% ---------------------
function s = push(v, s)
   s = {v s{1:end}};
end

% ---------------------
function [v s] = pop(s)
   v = s{1};
   s = s(2:end);
end

