matlab程序出错,我是新手

来源:百度知道 编辑:UC知道 时间:2024/06/18 10:05:50
P=[2.8626 6.3424 9.2437 9.6335;
2.8222 6.0765 9.3733 9.4176;
2.3115 6.2412 8.2046 8.6142;
2.2958 5.8089 8.3386 8.0483;
2.3390 6.0917 7.3696 9.0445;
2.3278 7.3597 7.3060 9.0247]';
T=[0 0 0 1;0 0 0 1;
0 0 1 0;0 0 1 0;
0 1 0 0;0 1 0 0]';
a=[5 10 15];
for i=1:3
net=newelm(minmax(P),[a(i),4],{'tansig','logsig'});
net.trainParam.epochs=100;
net=init(net);
net=train(net,P,T);
y=sim(net,P);
error(i,:)=y'-T;
end
hold off;
plot(1:4,error(1,:));
hold on;
plot(1:4,error(2,:),'-');
hold on;
plot(1:4,error(3,:),'--');
hold off;

三个错:

1. y跟T原本是同维的,你加上 y'反而不同维了。
2. error(i, :) = 这个命令只能定义一行,不能用y-T矩阵来赋值。
3. 这个画图plot(1:4, error(1, :))因此也就不对。

可以定义数组,比如error{i} = y - T;

或者 error(:, i) = y(:) - T(:);

BTW:
plot去掉1:4,直接plot(error(:, i))