MATLAB Answers

I am getting the following error in my code: "Unrecognized function or variable 'f'. " How do I correct this error? someone can help me in this TIA.

1 view (last 30 days)

Answers (1)

dpb on 31 Jul 2021
Edited: dpb on 31 Jul 2021
You're using f in line 1 while you don't define it until line 3.
Move line 1 to anywhere after but before use amp in line 11 -- I'd suggest it makes sense that it be line 10, the first calculation after all the inputs...
Code execution is purely linear -- just because the variable is defined somewhere in the code isn't enough; it must be defined in sequence of code execution before it is referenced.
Of course, calling a function that returns variables isn't strictly linear in execution in that the code in the function may be elsewhere in the function or another m-file or builtin, but the calling of the function must be in sequence such that any variables it defines (and returns) are available in order...
Walter Roberson
Walter Roberson on 1 Aug 2021
The point was to talk about why computer languages do not work the way the poster was expecting, so that the poster would better understand the difficulty.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!