Invalid syntax for calling function 'cond' on the path
조회 수: 22 (최근 30일)
이전 댓글 표시
Hi,
I want to extract data from a table called cond. As you can see from line 75 in the screenshot shown below, data Diameter corresponding to Drake can be successfully extracted using cond('Drake',:).Diameter.
However, when I was trying to write this into a function called findCF(), things went wrong at line 78 with an error message
Invalid syntax for calling function 'cond' on the path. Use a valid syntax or explicitly initialize 'cond' to make it a variable.
Can anybody tell me how to modify my code?
Thanks,
Armature
댓글 수: 0
채택된 답변
dpb
2021년 11월 19일
>> which -all cond
C:\ML_R2020b\toolbox\matlab\matfun\cond.m
>>
cond is a builtin MATLAB function (the condition number) unless you alias it as a variable as you have done in the earlier code.
But, inside the function findCF the table isn't defined as you didn't pass the variable cond to it nor even make provision to have it in the argument list so it isn't available.
All functions have their own workspace; even though you have defined a variable in the calling workspace it isn't visible inside a called function unless passed (or made global, but that's not a good solution).
To avoid using MATLAB functions as variable is one reason I use a prepended 't' on table variables so I would have named your table as tCond and the function definition would look like
function CF=findCF(tCond,Name,n,D,d)
and you would call it passing tCond as the first argument.
NB: The variable name in the caller and the callled routine are not required to be the same; they are associated by position in the argument list only, not by name; I only used the same one here out of being the fewest code changes needed to avoid aliasing and to pass the table.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!