MATLAB GUI计算器错误

时间:2013-01-11 20:08:27

标签: matlab user-interface matlab-guide

我正在开发一个计算器,使用MATLAB的指南从Julian时间来回转换为标准的IRIG时间。启动时,计算器可以正常工作,或者从另一个方向开始工作,但是在同一个会话中来回移动时会有某些东西被删除。我只使用两个按钮,这就是这两个按钮的回调代码:

% --- Executes on button press in convertjulian.
function convertjulian_Callback(hObject, eventdata, handles)
% hObject    handle to convertjulian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
value = handles.isec;

day = floor(value/86400);
remainder = (value/86400 - day)*86400;

hour = floor(remainder/3600);
remainder = (remainder/3600 - hour)*3600;

min = floor(remainder/60);
sec = (remainder/60 - min)*60;

set(handles.jday,'String',day);
set(handles.jhour,'String',hour);
set(handles.jmin,'String',min);
set(handles.jsec,'String',sec);

这是另一个回调:

% --- Executes on button press in convertirig.
function convertirig_Callback(hObject, eventdata, handles)
% hObject    handle to convertirig (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
seconds=handles.jday*86400+handles.jhour*3600+handles.jmin*60+handles.jsec;
set(handles.isec,'String',sprintf('%0.3f',seconds));

以下是我在运行MATLAB时遇到的错误:

使用handle.handle / set时出错 无效或已删除的对象。

时间转换错误> convertjulian_Callback(第124行) 集(handles.jday, '字符串',日);

gui_mainfcn出错(第96行)         feval(varargin {:});

时间转换错误(第42行)     gui_mainfcn(gui_State,varargin {:});

@(hObject,eventdata)timeconversion中的错误('convertjulian_Callback',hObject,eventdata,guidata(hObject))

评估uicontrol回调时出错

1 个答案:

答案 0 :(得分:0)

您将句柄视为数值。要从handles.isec获取值,您可以使用:

value = str2double(get(handles.isec, 'String'));

所有'j'手柄都是相似的。