在matlab中运行下列.m文件后出错,
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/31 20:00:50
在matlab中运行下列.m文件后出错,
factorial.m
function fact=factorial(u)
%
% factorial function used to demonstrate the use of
% function m-file in MATLAB
%
fact = 1;
if u>0
for i=1:u
fact=fact*i;
end
end
运行后出错提示“?Error:File:E:\MATLAB7\work\mydemo.m Line:2 Column:1
Function definitions are not permitted at the prompt or in scripts.”
factorial.m
function fact=factorial(u)
%
% factorial function used to demonstrate the use of
% function m-file in MATLAB
%
fact = 1;
if u>0
for i=1:u
fact=fact*i;
end
end
运行后出错提示“?Error:File:E:\MATLAB7\work\mydemo.m Line:2 Column:1
Function definitions are not permitted at the prompt or in scripts.”
![在matlab中运行下列.m文件后出错,](/uploads/image/z/7532094-30-4.jpg?t=%E5%9C%A8matlab%E4%B8%AD%E8%BF%90%E8%A1%8C%E4%B8%8B%E5%88%97.m%E6%96%87%E4%BB%B6%E5%90%8E%E5%87%BA%E9%94%99%2C)
那啥, 你不会是把factorial.m写在第一行了吧.