これはおそらく単純な問題であることはわかっていますが、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