MATLAB: How to replace variable name in function handle functionhandles I have a function handle as given below f = @(x1,x2) x1*x2 and I want to change variable name to f = @(x) x(1)*x(2) Please help me Thanks PS: The function is just for illustration purpose Best Answer Hi,for me this worked:f = @(x1,x2) x1*x2f = string(char(f));f = replace(f,"@(x1,x2)","@(x)");f = replace(f,["x1","x2"],["x(1)","x(2)"]);f = str2func(f)result is:f = function_handle with value: @(x1,x2)x1*x2f = function_handle with value: @(x)x(1)*x(2)Best regardsStephan Related SolutionsMATLAB: Force “resolution” of imbricated handles No.However you can sometimes use symbolic toolbox and matlabFunction MATLAB: Could you help me please? You have to make vectors out of them, then it works:f = @(x) x.^3+2; % Changed ‘inline’ To Anonymous Functionx1=2; x2=-2; x3=4;[Fmin,ix] = min([f(x1),f(x2),f(x3)]); % Vector Of ‘f(x)’x = [x1 x2 x3]; % Vector Of ‘x’xFmin = x(ix) % ‘argmin’ Related QuestionWhat does ‘@’ mean in a matlab expressionHow to define a vector of symbolic functionsNumber of input parameters of a function.Different results in symbol integrationAdding functions of the same variable to form a new function
Best Answer