Effacer les filtres
Effacer les filtres

GUI Matrix dimensions must agree.

2 vues (au cours des 30 derniers jours)
tsai kai shung
tsai kai shung le 31 Oct 2017
Commenté : Walter Roberson le 31 Oct 2017
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 31 Oct 2017
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 commentaires
tsai kai shung
tsai kai shung le 31 Oct 2017
Modifié(e) : Walter Roberson le 31 Oct 2017
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 le 31 Oct 2017
if strcmp(word, '40')
set(handles.text2,'string','40')
else
set(handles.text2,'string','error');
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 迁移使用 GUIDE 创建的 App dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!