Matlab GUI - How to get the previous value entered from a callback function?

Posted by Graham on Stack Overflow See other posts from Stack Overflow or by Graham
Published on 2010-05-30T15:46:07Z Indexed on 2010/05/30 15:52 UTC
Read the original article Hit count: 222

Filed under:
|
|

Hi, I know that this is probably a simple problem but I am new to Matlab GUI's and basically want to get the old value which used to be stored in the text box to replace the value which has just been entered. E.g.

  1. Text box contains a valid string,
  2. User enters invalid string,
  3. Callback func, validates input and realises new input is an error and reverts to the old previous value.

How should this be implemented or done? Atm I am just using the get and set property values. Below is some sample code:

function sampledist_Callback(hObject, eventdata, handles)
% hObject    handle to sampledist (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of sampledist as text
%        str2double(get(hObject,'String')) returns contents of sampledist as a double

input = str2double(get(hObject,'String'));
if(input < 0 || input > 500)
    errordlg('Sampled Dist. must be > 0 and < 500','Sample Dist - Input Error');
    set(handles.sampledist,'String',['10']); %<--- I would like this value 10 to be the previous entry!
    guidata(hObject,handles);
else
   set(handles.sampledist,'String',['',input]);
   guidata(hObject,handles);
end

© Stack Overflow or respective owner

Related posts about gui

Related posts about matlab