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 (최근 30일)

답변 (1개)

dpb
dpb 2021년 7월 31일
편집: dpb 2021년 7월 31일
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
dpb
dpb 2021년 7월 31일
"...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 2021년 8월 1일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by