Why does it appear "Error: Function definitions are not permitted in this context" when I run the following function file?
1 次查看(过去 30 天)
显示 更早的评论
I have two files for running:
The first one is a script I named preambulo.m which runs ok. The second one is a function which I named final_project_mc.m, when I run this file, it appears the error that I mentioned in the initial question, and I don't know why this is happening. In order to do this exercise you need to run first preambulo.m and then final_project_mc. M.
I would really appreciate any help with this problem.
0 个评论
采纳的回答
dpb
2015-7-2
As the error says, you can't directly execute an m-file which defines a function; you Call the function from a script or another function.
To call the function you would simply incorporate the line
final_project_mc(b)
at the end of the script which would return the output array at the command line as the default variable ans or assign it to a variable as
end_result = final_project_mc(b);
See
doc function % for more details
and section on programming for how scripts and functions work in the "Getting Started" section.
3 个评论
Image Analyst
2015-7-3
But you marked it as solved. I almost didn't look at it but I wanted to add my answer below.
dpb
2015-7-3
The thing is that the error is not in the file you're showing; it looks fine to me.
Somewhere, though, you have the problem both IA and I have described--we needs must see the actual lines being executed at the command line and the resulting error in context to be able to see precisely where it is; all we have is the symptom but not the root place it occurred. Or, perhaps, the file you're attaching isn't actually the one being referenced but another that is aliasing the one you think you're using.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!