please help me in this code how to over come from this error i will be posting my code
Show older comments
clear;clc;
One= [-1 1 -1 -1 -1, -1 1 -1 -1 -1,-1 1 -1 -1 -1,-1 1 -1 -1 -1,-1 1 -1 -1 -1,-1 1 -1 -1 -1,-1 1 -1 -1 -1,];
Two= [-1 -1 1 -1 -1, -1 1 -1 1 -1, 1 -1 -1 -1 1, -1 -1 -1 1 -1, -1 -1 1 -1 -1, -1 1 -1 -1 -1,1 1 1 1 1];
Three=[-1 1 1 1 -1,-1 -1 -1 1 -1, -1 -1 -1 1 -1, -1 -1 1 1 -1, -1 -1 -1 1 -1, -1 -1 -1 1 -1, -1 1 1 1 -1];
Four= [1 -1 -1 -1 -1,1 -1 -1 -1 -1,1 -1 -1 -1 -1,1 -1 1 -1 -1, 1 1 1 1 1, 1 1 1 1 1, -1 -1 1 -1 -1];
Five= [-1 1 1 1 1, -1 1 -1 -1 -1, -1 1 -1 -1 -1, -1 1 1 1 1, -1 -1 -1 -1 1, -1 -1 -1 -1 1, -1 1 1 1 1];
Six= [1 1 1 1 -1, 1 -1 -1 -1 -1, 1 -1 -1 -1 -1, 1 1 1 1 -1, 1 -1 -1 1 -1, 1 -1 -1 1 -1, 1 1 1 1 -1];
Seven= [-1 -1 1 1 1, -1 -1 1 1 1, -1 -1 -1 -1 1, -1 -1 -1 -1 1, -1 -1 -1 -1 1, -1 -1 -1 -1 1, -1 -1 -1 -1 -1];
Eight= [1 1 1 1 1, 1 -1 -1 -1 1, 1 -1 -1 -1 1, 1 1 1 1 1, 1 -1 -1 -1 1, 1 -1 -1 -1 1, 1 1 1 1 1];
Nine= [1 1 1 1 -1, 1 -1 -1 1 -1, 1 1 1 1 -1, -1 -1 -1 1 -1, -1 -1 -1 1 -1, -1 -1 -1 1 -1, -1 -1 -1 1 -1];
Plus= [-1 -1 -1 -1 -1, -1 -1 1 -1 -1, -1 -1 1 -1 -1, 1 1 1 1 1, -1 -1 1 -1 -1, -1 -1 1 -1 -1, -1 -1-1 -1 -1 ];
Minus= [-1 -1 -1 -1 -1,-1 -1 -1 -1 -1,-1 -1 -1 -1 -1,1 1 1 1 1, -1 -1 -1 -1 -1,-1 -1 -1 -1 -1,-1 -1 -1 -1 -1, ];
Zero= [ 1 1 1 1 1, 1 1 1 1 1, 1 -1 -1 -1 1, 1 -1 -1 -1 1, 1 -1 -1 -1 1, 1 1 1 1 1, 1 1 1 1 1];
%Patterns= [One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Plus, Minus];
%w=One*One'+Two*Two'+Three*Three'+Four*Four'+Five*Five'+Six*Six'+Seven*Seve
%n'+Eight*Eight'+Nine*Nine'+Plus*Plus'+Minus*Minus';
w=0;
rows= 7; columns= 5;
Patterns= [One, Two, Four, Five, Six, Seven, Eight, Nine, Minus];
for loop=1:min(size(Patterns))
w=w+ Patterns(:,loop)*Patterns(:,loop)';
end
w=w-w(1,1)*eye(length(w));
for kk=1:min(size(Patterns))
E(kk)= -0.5*Patterns(:,kk)'*w*Patterns(:,kk);
end
% for outerloop=1:min(size(Patterns))
input_char=[-1 -1 1 -1 -1, -1 1 1 1 -1, 1 -1 -1 -1 1, -1 -1 -1 1 -1, -1 -1 1 -1 -1, -1 1 -1 -1 1,1 1 1 1 1];
output_char= input_char;
%Natural order updation
E_pat=-0.5*input_char'*w*input_char;
E_pat_new= E_pat;
flag=1;
iteration=0; while(flag)
iteration= iteration +1;
for kk=1:length(Patterns)
output_char(kk)= sign(w(kk,:)*output_char);
end
E_pat= E_pat_new;
E_pat_new=-0.5*output_char'*w*output_char;
if E_pat== E_pat_new
flag= 0;
elseif iteration >=250
flag= 0;
end
end
for loop=1:rows
char_in(loop,:)=input_char(((loop-1)*columns+1):((loop-1)*columns+columns))';
char_out(loop,:)=output_char(((loop-1)*columns+1):((loop-1)*columns+columns))';
end
figure('Position', [431 273 381 518]);
subplot(211);imagesc(char_in);title('Input pattern', 'FontSize', 16);
subplot(212);imagesc(char_out);title('Output pattern', 'FontSize', 16);
5 Comments
Robert Cumming
on 13 Apr 2012
format the code and post the actual error message.
Harshitha Kotian
on 15 Apr 2012
Jan
on 15 Apr 2012
Posting the error message means actually posting the complete error message, which include the line, which causes the error.
Harshitha Kotian
on 16 Apr 2012
Harshitha Kotian
on 16 Apr 2012
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!