フィルターのクリア

GUI Matrix dimensions must agree.

3 ビュー (過去 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 Center および File Exchange迁移使用 GUIDE 创建的 App についてさらに検索

Community Treasure Hunt

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

Start Hunting!