Q:

Storing variables inside function Matlab

function abc= calculate(obj)
ag=obj.turns*d/c;
end

I tried using:
temp=num2cell(obj.turns)
            s=temp{:}

But the value is replaced every time.
How can I store the value of obj.turns in this function? The value changes every time the function is called.

A:

If I interpret what you want correctly, you should use a persistent variable. Here's an example:
function abc = calculate(obj)

  persistent storedTurns;
  if isempty(storedTurns)
    storedTurns = obj.turns;
  end

  ag = storedTurns*d/c;
  ...

end

The first time you call calculate, the value in obj.turns will be placed in storedTurns. That value will stay fixed for every other time you call calculate, ignoring from that point on whatever new values may be present in the variable obj that you pass in.

