Neural Network training help
Show older comments
Hi all, I am seeking some help with my matlab code, to recognize my full name when testing the the program.
Every time I run the code, it works fine with no erros but when i click on train from the GUI menu designed, an error shows up says:
Error using plot
Vectors must be the same length.
Error in assi2NN (line 28)
plot(data,target,'*',data,Y,'o'),legend('data','target');
(My data taget and data input files are attached:)
Thanks for any help.
Bellow is my full code:
clear all
clc
close all
warning off
while(true)
k=menu('ANN','train','test','close')
if k==1
%%%read the data
fid=fopen('datain.txt','rt');
data=fscanf(fid,'%f',[9,inf])
%%%read data target
fid=fopen('datatar.txt','rt');
target=fscanf(fid,'%f',[1,inf])
whos data target
%%%ANN model
a=minmax(data);
net=newff([a],[10 5 1],{'tansig','tansig','tansig'},'trainlm');
net=init(net);
% view(net)
figure(1)
Y=sim(net,data);
plot(data,target,'*',data,Y,'o'),legend('data','target');
title('Before')
%%%%%Training param
net.trainParam.epochs = 500;
[net,tr]=train(net,data,target);
Y=sim(net,data);
figure(2)
plot(data,target,'*',data,Y,'o'),legend('data','target');
title('After')
save net
end
%
if k==2;
j=menu('Choose','R','A','K','A','N','T','A','M','E','R','close')
%
if j==1
R = [ 0.1250 0.2500 0.3750 0.6500 1.0000 0 0 0 0 ]';
load net
Y=sim(net,R)
if Y < -0.75
disp ('This is aplhabet R')
end
end
%
if j==2
A = [ 0.1111 0.2222 0.3333 0.4444 0.6667 0.7778 0.8889 1.0000 0]';
load net
Y=sim(net,A)
if Y < -0.25 && Y >= -0.75
disp ('This is aplhabet A')
end
end
%
if j==3
K = [ 0.1111 0.3333 0.4444 0.5556 0.6667 0.7778 1.0000 0 0 ]';
load net
Y=sim(net,K)
if Y > -0.25 && Y <= 0.75
disp ('This is aplhabet K')
end
end
%
if j==4
A = [ 0.1111 0.4444 0.5556 0.6667 0.7778 0.8889 1.0000 0 0 ]';
load net
Y=sim(net,A)
if Y > 0.25 && Y <= 0.75
disp ('This is aplhabet A')
end
end
%
if j==5
N=[ 0.1111 0.3333 0.4444 0.5556 0.6667 0.7778 1.0000 0 0 ]';
load net
Y=sim(net,N)
if Y >= 0.50
disp ('This is aplhabet N')
end
end
%
if j==6
T = [ 0.1250 0.2500 0.3750 0.6500 1.0000 0 0 0 0 ]';
load net
Y=sim(net,T)
if Y < -0.75
disp ('This is aplhabet T')
end
end
%
if j==7
A = [ 0.1111 0.2222 0.3333 0.4444 0.6667 0.7778 0.8889 1.0000 0]';
load net
Y=sim(net,A)
if Y < -0.25 && Y >= -0.75
disp ('This is aplhabet A')
end
end
%
if j==8
M = [ 0.1111 0.3333 0.4444 0.5556 0.6667 0.7778 1.0000 0 0 ]';
load net
Y=sim(net,M)
if Y > -0.25 && Y <= 0.75
disp ('This is aplhabet M')
end
end
%
if j==9
E = [ 0.1111 0.4444 0.5556 0.6667 0.7778 0.8889 1.0000 0 0 ]';
load net
Y=sim(net,E)
if Y > 0.25 && Y <= 0.75
disp ('This is aplhabet E')
end
end
%
if j==10
R=[ 0.1111 0.3333 0.4444 0.5556 0.6667 0.7778 1.0000 0 0 ]';
load net
Y=sim(net,R)
if Y >= 0.50
disp ('This is aplhabet R')
end
end
end
%
if k==3
break;
end
end
Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!