0
votes

I'm Developing a calculator that converts back and forth from a Julian time to a standard IRIG time using MATLAB's GUIDE. When started, the calculator works fine going one way, or starting out going the other way, but somehow something gets deleted when going back and forth in the same session. I'm only using two buttons, and this is what the code looks like for the callbacks of those two buttons:

% --- 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);

Here is the other callback:

% --- 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));

And here is the error that I get in MATLAB when I'm running it:

Error using handle.handle/set Invalid or deleted object.

Error in timeconversion>convertjulian_Callback (line 124) set(handles.jday,'String',day);

Error in gui_mainfcn (line 96) feval(varargin{:});

Error in timeconversion (line 42) gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)timeconversion('convertjulian_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

1

1 Answers

0
votes

You are treating handles as numeric values. To get the value from a handles.isec, you can use:

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

All the 'j' handles will be similar.