Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我知道这可能是一个简单的问题,但是我对Matlab GUI还是陌生的,基本上是想获取以前存储在文本框中的旧值来替换刚刚输入的值。例如
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']); % 500) errordlg('Sampled Dist. must be > 0 and < 500','Sample Dist - Input Error'); set(handles.sampledist,'String',num2str(handles.sampledistPrev)); %reset value be the previous entry! guidata(hObject,handles); %# Note that you don't need to save the handles structure unless %# you have changed a user-defined value like sampledistPrev %# It may still be useful to do it so you always remember else set(handles.sampledist,'String',['',input]); %# also update the reset value handles.sampledistPrev = input; guidata(hObject,handles); end 更多&回答... |
![]() |
![]() |