How to call a function by assigning a string to a variable?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arif Ahmed
am 21 Dez. 2020
Bearbeitet: Arif Ahmed
am 21 Dez. 2020
Please consider the following:
I write a function file named 'case_a' from a function 'test'.
output = 'case_a';
matlabFunction(test, 'file', output, 'Optimize', false);
Because my variable output is going to be changing every iteration, I would like to be able to call the actual output function. Specifically, let's say I run a new simulation and I would like to call the function case_a(input) with some input vector. But I would like to first assign the saved function file to my 'output' variable such that I can call output(input) in every run. In this case output should actually be the case_a. In another case I want to assign 'case_b' in output, such that I can still call it as output(input).
Regards
3 Kommentare
Stephen23
am 21 Dez. 2020
The description is not very clear, but it does have quite a smell to it:
"... should actually be the case_a. In another case I want to assign 'case_b' in output..."
Akzeptierte Antwort
Weitere Antworten (1)
Matt J
am 21 Dez. 2020
Bearbeitet: Matt J
am 21 Dez. 2020
Since you've set Optimize=false, I don't know why you are sending the result to a file. You may as well just use the output of matlabFunction() directly,
fun=matlabFunction(test);
fun(arg1,arg2,...)
3 Kommentare
Matt J
am 21 Dez. 2020
But once fun is created, you can reuse it and/or save it to a file. Why would you need to call matlabFunction every time?
Aside from that, if matlabFunction is taking a long time, it likely means you are doing something symbolically that should really be done numerically.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!