Borrar filtros
Borrar filtros

Funny Behavior When Doing Substitution w/ matlabFunction Files

1 visualización (últimos 30 días)
I have a symbolic function that I convert to a numeric file using matlabFunction. Then, using the find_and_replace function from the file exchange I substituted out several arguments and replace them with elements of a matrix.
So whereas before my function was something like
function H = H(arg1a,arg2a,arg1b,arg2b)
H = arg1a + arg2a + arg1b + arg2b;
end
It is now
function H = H(arg_a,arg_b)
H = arg_a(1) + arg_a(2) + arg_b(1) + arg_b(2);
end
Two odd things happen:
  1. If I try to run the second function I get the error 'Not enough input arguments.'
  2. If I a) open the script b.) delete a semicolon c.) save d.) add the semicolon e.) save, then everything runs well.
Any ideas of what might be going on here?

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Dic. de 2015
MATLAB did not detect that you had modified the file and used the one that was already in its cache. It would also have worked if you had used
clear H
When-ever you use code to modify a .m file that you have executed, you should "clear" the function.
Note that there is a better way of doing what you did. See http://www.mathworks.com/help/symbolic/matlabfunction.html#zmw57dd0e82644 and the example "Now, convert an expression r to a MATLAB function whose second input argument is a vector."
  2 comentarios
William Wooley
William Wooley el 17 de Dic. de 2015
Two great tips. Thanks! I can't believe I overlooked that part of the documentation.
Walter Roberson
Walter Roberson el 17 de Dic. de 2015
I think it might be relatively new. I only noticed that in the documentation a few months ago.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by