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.

4 views (last 30 days)

Answers (1)

dpb
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...
  3 Comments
dpb
dpb on 31 Jul 2021
"...computer languages which permitted the statements in any order." @Walter Roberson
Well, yes, but MATLAB is not one of those were so pretty-much a moot point here... :)
The input deck parser for many of the old nuclear design codes was designed the same way so that one make changes only to the original deck by substituting cards with the same sequence number with the new data for timesteps, say. A most handy innovation from Bettis Atomic Power Labs lo! those many years ago...
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!