0

我正在开发一个计算器,它使用 MATLAB 的 GUIDE 从儒略时间到标准 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 (line 124) set(handles.jday,'String',day);

gui_mainfcn 中的错误(第 96 行) feval(varargin{:});

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

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

评估 uicontrol 回调时出错

4

1 回答 1

0

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

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

所有的“j”句柄都是相似的。

于 2013-01-11T20:47:33.730 回答