필터 지우기
필터 지우기

GUI Matrix dimensions must agree.

조회 수: 2 (최근 30일)
tsai kai shung
tsai kai shung 2017년 10월 31일
댓글: Walter Roberson 2017년 10월 31일
function numberdetect_Callback(hObject, eventdata, handles)
global t
global t1
t=timer('TimerFcn',{@timerCallback3,handles},'ExecutionMode', 'fixedDelay','Period', 0.1);
guidata(hObject,handles);
stop(t1);
start(t);
function timerCallback3(hObject, eventdata, handles)
global vid
global t
global frame
global c
if (vid==-1)
msgbox('請首先進行預覽!');
stop(t);
return;
end
frame=getsnapshot(vid);
imagen = rgb2gray(frame);
threshold = graythresh(imagen);
i_bw = ~im2bw(imagen,threshold);
i_bw2 = bwareaopen(i_bw,30);
i_bw3 = imclearborder(i_bw2);
re=i_bw3;
load templates
[fl re]=lines(re);
imgn=fl;
[L Ne] = bwlabel(imgn);
word = [];
for n=1:Ne
[r,d] = find(L==n);
n1=imgn(min(r):max(r),min(d):max(d));
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
word = [word letter];
end
if word == '40'
set(handles.text2,'string','40');
else
set(handles.text2,'string','no');
end
axes(handles.axesshow);
imshow(imagen);
end
function r = Corr2(A,B)
A = A - mean2(A);
B = B - mean2(B);
r = sum(sum(A.*B))/sqrt(sum(sum(A.*A))*sum(sum(B.*B)));
function [fl re]=lines(im_texto)
im_texto=clip(im_texto);
fl=im_texto;%Only one line.
re=[ ];
function img_out=clip(img_in)
[f c]=find(img_in);
img_out=img_in(min(f):max(f),min(c):max(c));%Crops image
I am use this function on guide but show the error: Matrix dimensions must agree.

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 31일
You have
if word == '40'
Do not use "==" to compare character vectors. == does element-by-element comparison, word(1) compared to the first character of '40', word(2) compared to the second character of '40', word(3) compared to ... error, there is no third character of '40' .
You should use strcmp() to compare anything that is not known for certain to be a single character.
  댓글 수: 6
tsai kai shung
tsai kai shung 2017년 10월 31일
편집: Walter Roberson 2017년 10월 31일
xx = '40';
aa = strcmp(word,xx);
if aa == 1
set(handles.text2,'string','40');
else
set(handles.text2,'string','error');
end
i use this can success thank you!
Walter Roberson
Walter Roberson 2017년 10월 31일
if strcmp(word, '40')
set(handles.text2,'string','40')
else
set(handles.text2,'string','error');
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 迁移使用 GUIDE 创建的 App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!