How to got correct answer in if condition in GUI?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, after retrieve all data about driver got other problem, with if condition. When car number plate correct if condition work great, but if i do task that car number plate not in database i got error. Please help me, where i do mistake. Code add below. P.S. Sorry for my bad english
conn = database('baze', 'root', 'root', 'Vendor', 'MYSQL', 'Server', 'localhost', 'PortNumber', 3306);
setdbprefs('datareturnformat','structure');
word = get(handles.edit4,'String');
if iscell(word) && numel(word) == 1
word = word{1};
end
if ~ischar(word) || isempty(word);
error('A valid string must be supplied!');
end
sqlquery = ['select vardas, pavarde, laipsnis, pareigos, telefonas, marke, numeris, tarnyba, nuotrauka from info '...
'where numeris = ' '''' word ''''];
curs = exec(conn, sqlquery);
setdbprefs('DataReturnFormat','cellarray');
curs = fetch(curs);
numeris = curs.data{1,7};
vardas = curs.data{1,1};
pavarde = curs.data{1,2};
laipsnis = curs.data{1,3};
pareigos = curs.data{1,4};
telefonas = curs.data{1,5};
marke = curs.data{1,6};
tarnyba = curs.data{1,8};
nuotrauka = curs.data(1,9);
set(handles.edit5,'string',vardas);
set(handles.edit6,'string',pavarde);
set(handles.edit7,'string',laipsnis);
set(handles.edit8,'string',pareigos);
set(handles.edit9,'string',telefonas);
set(handles.edit10,'string',marke);
set(handles.edit11,'string',numeris);
set(handles.edit12,'string',tarnyba);
axes(handles.axes4);
nuotrauka = nuotrauka{1};
jimage = javax.imageio.ImageIO.read(java.io.ByteArrayInputStream(typecast(nuotrauka, 'uint8')));
height = jimage.getHeight;
width = jimage.getWidth;
pixels = reshape(typecast(jimage.getData.getDataStorage, 'uint8'), [3,width,height]);
img = cat(3, ...
transpose(reshape(pixels(3,:,:), [width,height])), ...
transpose(reshape(pixels(2,:,:), [width,height])), ...
transpose(reshape(pixels(1,:,:), [width,height])));
imshow(img);
a = ('ENTRY');
b = ('DO NOT ENTRY');
if word == curs.data{1,7}
set(handles.text13,'foregroundcolor','green');
set(handles.text13,'string',a);
else
set(handles.text13,'foregroundcolor','red');
set(handles.text13,'string',b);
end
close(curs);
close(conn);
clear all
댓글 수: 2
Jan
2016년 12월 18일
If you get an error message, please post a complete copy of it. It is much easier to understand a problem, if it is known.
채택된 답변
Walter Roberson
2016년 12월 26일
if isempty(curs.data)
%there was no match...
else
%okay to use the data
end
댓글 수: 11
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!