MATLAB程序不能运行,求指出错误并修正
Error:File:C:\MATLAB7\work\Untitledshasha.m Line:25 Column:1
Function definitions are not permitted at the prompt or in scripts.
xa=[0.291052416 0.327997543 0.242080262 0.138869779]
xb=[0.231310139 0.290718037 0.258610411 0.162162162 ]
x=[0.297297297 0.135135135 0.396396396 0.171171171
0.27027027 0.153153153 0.414414414 0.162162162
0.27027027 0.063063063 0.45045045 0.216216216
0.423423423 0.288288288 0.18018018 0.108108108
0.234234234 0.108108108 0.423423423 0.234234234
0.351351351 0.126126126 0.396396396 0.126126126
0.351351351 0.189189189 0.36036036 0.099099099
0.279279279 0.189189189 0.369369369 0.162162162
0.207207207 0.153153153 0.432432432 0.207207207
0.181818182 0.136363636 0.409090909 0.272727273
0.354545455 0.5 0.1 0.045454545
0.327272727 0.5 0.145454545 0.027272727
0.254545455 0.518181818 0.127272727 0.1
0.3 0.5 0.118181818 0.081818182
0.290909091 0.645454545 0.063636364 0
0.363636364 0.463636364 0.090909091 0.081818182
0.354545455 0.263636364 0.136363636 0.245454545
0.290909091 0.5 0.090909091 0.118181818
0.218181818 0.563636364 0.072727273 0.145454545
0.2 0.563636364 0.063636364 0.172727273]
function [da,db]=chen(x,xa,xb)
A=zeros(1,20); B=zeros(1,20); C=zeros(1,20);
a=1; b=1; c=1;
for i=1:20
da=sqrt((x(i,1)-xa(1,1)).^2+(x(i,2)-xa(1,2)).^2+(x(i,3)-xa(1,3)).^2+(x(i,4)-xa(1,4)).^2);
db=sqrt((x(i,1)-xb(1,1)).^2+(x(i,2)-xb(1,2)).^2+(x(i,3)-xb(1,3)).^2+(x(i,4)-xb(1,4)).^2);
if(dadb)
B(1,b)=i+20; b=b+1;
end
if(da==db)
C(1,c)=i+20; c=c+1;
end
end
A
B
C
MATLAB程序不能运行,求指出错误并修正
答案:1 悬赏:80 手机版
解决时间 2021-04-15 07:55
- 提问者网友:雪舞兮
- 2021-04-14 11:34
最佳答案
- 五星知识达人网友:老鼠爱大米
- 2021-04-14 12:22
1、你如果就想写一个脚本,就不要定义那个函数,也就是把function [da,db]=chen(x,xa,xb)这行去掉.
2、如果想写一个函数,就把数据单独储存,再调用这个函数,也就是说function [da,db]=chen(x,xa,xb)在第一行,而且文件名也叫chen.m
我估计你应该是第一种情况,希望我的回答有用.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯