MATLAB: Guide- coma

guide

Hi, can you help me please? I have problem with comma ",". I need this:
If I write number into edittext with coma for example 4,3 or 34,4534 or 2342,44 , then I need to write for example into statictext "error". . . else into statictext "ok".
It is possible?

Best Answer

Generally we like to see that you have put effort into trying to solve your problem. It looks like you have been trying things here: http://www.mathworks.com/matlabcentral/answers/32252-field-text-number and that this is not exactly an overlapping question ...
I start by defining a function iscomma
function iscomma(src, h)
if strfind(get(src, 'string'), ',')
set(h, 'string', 'error');
else
set(h, 'string', 'ok');
end
Then I create two uicontrols and set the callback of the edit box to iscomma
h1 = uicontrol('style', 'edit');
h2 = uicontrol('style', 'text', 'units', 'normalized', 'position', [0.5, 0.5, 0.5, 0.5]);
set(h1, 'Callback', @(src, evt)iscomma(src, h2))