我知道这可能是一个简单的问题,但我是 Matlab GUI 的新手,基本上想要获取曾经存储在文本框中的旧值来替换刚刚输入的值。例如
- 文本框包含一个有效的字符串,
- 用户输入无效字符串,
- 回调函数,验证输入并意识到新输入是错误的并恢复为旧的先前值。
这应该如何实施或完成?Atm 我只是使用 get 和 set 属性值。下面是一些示例代码:
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