This assignment writes a 'char' value into a 'double' type.
Show older comments
if true
function word = fcn(L,Ne,re,templates)
word = [];
for n=1:Ne
[r,c] = find(L==n);
% Extract letter
n1=re(min(r):max(r),min(c):max(c));
% Resize letter (same size of template)
img_r=imresize(n1,[42 24]);
comp=[ ];
for n=1: 24 : 240
sem=Corr2(templates(1:42,n:n+23),img_r);
comp=[comp sem];
end
vd=find(comp==max(comp));
%*-*-*-*-*-*-*-*-*-*-*-*-*-
if vd==1
letter='1';
elseif vd==2
letter='2';
elseif vd==3
letter='3';
elseif vd==4
letter='4';
elseif vd==5
letter='5';
elseif vd==6
letter='6';
elseif vd==7
letter='7';
elseif vd==8
letter='8';
elseif vd==9
letter='9';
else
letter='0';
end
% Letter concatenation
word = [word letter]; end
end end i use the matlab code on simulink but show the error!
Answers (1)
Rik
on 19 Oct 2017
You should change various things. See the version below.
function word = fcn(L,Ne,re,templates)
%initializing to empty char can be done with word='';
word = char(zeros(1,Ne));
for n=1:Ne
[r,c] = find(L==n);
% Extract letter
n1=re(min(r):max(r),min(c):max(c));
% Resize letter (same size of template)
img_r=imresize(n1,[42 24]);
comp=zeros(1,10);%explicit pre-allocation
for m=1: 24 : 240%conflicted index, also changed to m on next line
sem=Corr2(templates(1:42,m:m+23),img_r);
comp((m+23)/24)=sem;
end
vd=find(comp==max(comp));
%*-*-*-*-*-*-*-*-*-*-*-*-*-
letter=sprintf('%d',mod(vd,10));
%mod(vd,10) keeps 1:9 the same and changes 10 to 0.
% Letter concatenation
word(n) = letter;
end
2 Comments
tsai kai shung
on 19 Oct 2017
Rik
on 19 Oct 2017
The only differences between my function and yours, is that mine is more compact, should be a tiny bit faster, doesn't overwrite n in the second loop, and returns a char vector instead of a double vector.
If you can use your function, you can also use mine. I hardly ever use Simulink at all, so I don't understand your question and can't answer it.
Categories
Find more on Simulink 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!