MATLAB: Undefined operator ‘-‘ for input arguments of type ‘cell’.

recursive handle_function

Hello I am trying to optimize a function and I defined the objective function as follow:
Tp=Scope{1,1}.values(2:36,7);
T1= Scope{1,1}.values(2:36,9);
To= cell(35,1);
To{1}=70;
for i=2:36
To{i} = @(k) To{i-1} + (k)*(T1(i)- To{i-1} )
end
obj=(sum(Tp-To).^2)
end
Yet when running the function I keep getting the error Undefined operator '-' for input arguments of type 'cell'. Can you please help

Best Answer

Tp = Scope{1,1}.values(2:36,7);
T1 = Scope{1,1}.values(2:36,9);
To = cell(35,1);
To{1} = @(k) 70;
for i=2:36
To{i} = @(k) To{i-1}(k) + (k)*(T1(i)- To{i-1}(k) );
end
obj = @(k) (sum(Tp-To(k)).^2);
This is not going to be efficient.