필터 지우기
필터 지우기

This assignment writes a 'char' value into a 'double' type.

조회 수: 6 (최근 30일)
tsai kai shung
tsai kai shung 2017년 10월 19일
댓글: Rik 2017년 10월 19일
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!

답변 (1개)

Rik
Rik 2017년 10월 19일
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
tsai kai shung
tsai kai shung 2017년 10월 19일
this function is matlab function on simulink so simulink can use char value?
Rik
Rik 2017년 10월 19일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink 函数에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!