Changing Matlab Function in a Loop

I want to slightly modify the MATLAB function at each step of the for loop. My function is too complicated to write as anonymous. Is there a way to change the function of the m file at each step?

Additional information: My function is equations with 8 inputs and infinitely many solutions. I want to set 7 inputs and then use fsolve to find the 8th. change some of these 7 fixed inputs in a for loop so that I can plot the solutions to this equation.

+3
source share
1 answer

Make an example with two inputs from which you want to change it. Since you claim that your function is really complex, write it to a file with the name complicated.mthat we save in the Matlab path.

function out = complicated(v1,v2,x)

out = v1*x-v2*x.^2;

, v1 v2

figure,hold on
for v1 = 1:5
   for v2 = 1:5
      %# define the function
      myFun = @(x)complicated(v1,v2,x);
      %# find the roots
      fzero(myFun,1)
      %# plot the function
      plot(-5:0.1:5,myFun(-5:0.1:5))
   end
end
+5

Source: https://habr.com/ru/post/1763921/


All Articles