关于matlab编程,请教大侠

来源:百度知道 编辑:UC知道 时间:2024/05/02 17:44:19
请帮忙对每行语句进行注释,这是一个关于两个螺旋的,先在这里感谢了
%
%
% Load Training Data
load two_spiral.dat

% Construct training signal P and T
P=two_spiral(:,1:2)';
T=two_spiral(:,3)';

%Plot training signal
i=find(T>0.5); j=find(T<=0.5);
x=P(1,i); y=P(2,i);
x1=P(1,j); y1=P(2,j);
plot(x,y,'o',x1,y1,'+')

%Push a key to continue
disp('Push a key to continue')
pause

%Define a neural network and train it with the training data
net = newff([-0.5 0.5; -0.5 0.5], [18 1], {'tansig' 'logsig'});
net.trainParam.epochs = 5000;
net = train(net,P,T);

%Generate input data randomly
x2=rand(1,5000)-0.5;
y2=0.8*rand(1,5000)-0.4;
P2=[x2;y2];

%Simulate the trained network
T2 = sim(net,P2);

%Check the generalization ability of the trained network
ii=find(T2>0.5)
plot(x,y,'o',x1,y1,'+'

你要求的工作量挺大的.

load two_spiral.dat %把数据文件two_spiral.dat 读取到工作区间

% Construct training signal P and T
P=two_spiral(:,1:2)'; %把数据矩阵two_spiral的第一第二行所有数据读取给P,(原本是第一第二列的,转置后就成行了)
T=two_spiral(:,3)'; %把数据矩阵two_spiral的第三行所有数据赋给T

%Plot training signal
i=find(T>0.5); j=find(T<=0.5); %寻找T(向量)中大于0.5元素的位置赋给I,如>> a=rand(1,5)
a =0.9501 0.2311 0.6068 0.4860 0.8913
>> i=find(a<0.5)
i =2 4

x=P(1,i); y=P(2,i); %把P矩阵的第一行,I列(应该是几数)的值赋给X,其他同理
x1=P(1,j); y1=P(2,j);
plot(x,y,'o',x1,y1,'+') %画X-Y图,在对应用O标记,其他同

%Push a key to continue
disp('Push a key to continue') %显示提示字符串'Push a key to continue'
pause %暂停,时间未定则直到你按下任意键后才继续

%Define a neural network and train it with the training data
net = newff([-0.5 0.5; -0.5 0.5], [18 1], {'tansig' 'logsig'}); %这个函数没用过,不敢误导
net.trainParam.epochs = 5000;