How to got correct answer in if condition in GUI?
1 view (last 30 days)
Show older comments
Gytis Raudonius
on 18 Dec 2016
Answered: Gytis Raudonius
on 30 Dec 2016
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 Comments
Jan
on 18 Dec 2016
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.
Accepted Answer
Walter Roberson
on 26 Dec 2016
if isempty(curs.data)
%there was no match...
else
%okay to use the data
end
11 Comments
More Answers (2)
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!