Function definition are not supported in this context. Functions can only be created as local or nested functions in code files.(clarification and application?)
8 ビュー (過去 30 日間)
古いコメントを表示
Hi! I've seen this question asked before but have been unable to properly understand the solution. I am getting the error message "Function definition are not supported in this context. Functions can only be created as local or nested functions in code files." when running this code:
status = function celldestiny2(A,i,j)
n = numneighbors(A,i,j);
disp('n e')
disp(num2str(n))
%mindre än 2 ensam o dör, alltså blir 0
if n < 2
status=dod
else if n == 2
%om död 2 grannar -> inget händer
if A(i,j)==0
status=dod
%om levande o 2 grannar -> inget händer
else
status=levande
end
else if n == 3
%om 3 grannar och TOM plats, föds ny.
if A(i,j)==0
status=levande
%om 3 grannar och lever -> inget händer.
else
status=levande
end
else if n > 3
status=dod
disp('svalt')
%mer än 3 grannar -> dör
end
end
end
end
A
end
Things I have tried to no success:
- deleting the A at the end
- checking if I'm missing any end statements (I shouldn't be, though I'm not sure if those at the end are correctly placed)
- changing the "status" from a word output to a value (0 or 1)
I've heard something about the function definition needing to be at the "end" of the file, but what does that mean and how do I apply it practically? Any help would be greatly appreciated :)
2 件のコメント
Dyuman Joshi
2023 年 10 月 2 日
That is not how functions are defined or called. The first line of your code does not follow the correct syntax.
回答 (1 件)
Image Analyst
2023 年 10 月 2 日
Try this as the first line to declare the function:
function status = celldestiny2(A,i,j)
To learn other fundamental concepts, invest 2 hours of your time here:
1 件のコメント
Image Analyst
2023 年 10 月 5 日
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
