Code covered by the BSD License  

Highlights from
Nuclear Medicine Calculator

image thumbnail
from Nuclear Medicine Calculator by Omer Demirkaya
It is a simple decay calculator with most of the nuclear medicine isotopes.

nucmedcalc(varargin)
function varargout = nucmedcalc(varargin)
% NUCMEDCALC M-file for nucmedcalc.fig
%      NUCMEDCALC, by itself, creates a new NUCMEDCALC or raises the existing
%      singleton*.
%
%      H = NUCMEDCALC returns the handle to a new NUCMEDCALC or the handle to
%      the existing singleton*.
%
%      NUCMEDCALC('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in NUCMEDCALC.M with the given input arguments.
%
%      NUCMEDCALC('Property','Value',...) creates a new NUCMEDCALC or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before nucmedcalc_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to nucmedcalc_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help nucmedcalc

% Last Modified by GUIDE v2.5 18-Apr-2009 13:17:41

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @nucmedcalc_OpeningFcn, ...
                   'gui_OutputFcn',  @nucmedcalc_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before nucmedcalc is made visible.
function nucmedcalc_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to nucmedcalc (see VARARGIN)

% Choose default command line output for nucmedcalc
handles.output = hObject;

% Update handles structure

handles.isotope = 'Tc-99m';
set(handles.edit_halflife,'String',getisotopehalflife1('Tc-99m'));
ss = mat2str(getisotopephotopeak(num2str(handles.isotope)));
ss(findstr(ss,' ')) = ',';
set(handles.edit_photopeak,'String',ss);
[t12,tunitnum]= getisotopehalflife1(num2str(handles.isotope));
[tunit,cf] = gethalflifeunit(tunitnum);
handles.isotopecorectionfactor = cf;
initialize_gui(handles.figure1, handles)

% Disclaimer
s = {'THIS SOFTWARE DOES NOT (A) MAKE ANY WARRANTY, EXPRESS OR IMPLIED',
    'WITH RESPECT TO THE USE OF THE INFORMATION PROVIDED HEREBY; NOR', 
    '(B) GUARANTEE THE ACCURACY,COMPLETENESS,USEFULNESS, OR ADEQUACY ',
    'OF ANY RESOURCES, INFORMATION,SYSTEM,PRODUCT,OR PROCESS ',
    'AVAILABLE AT OR THROUGH THIS SOFTWARE.'};
msgbox(s,'Disclaimer','modal');
guidata(hObject, handles);

% UIWAIT makes nucmedcalc wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = nucmedcalc_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on selection change in popupmenu_isotope.
function popupmenu_isotope_Callback(hObject, eventdata, handles)
contents = get(hObject,'String');
handles.isotope = contents{get(hObject,'Value')};
[t12,tunitnum]= getisotopehalflife1(num2str(handles.isotope));
[tunit,cf] = gethalflifeunit(tunitnum);
handles.isotopecorectionfactor = cf;
set(handles.edit_halflife,'String',getisotopehalflife1(num2str(handles.isotope)));
set(handles.text12,'String',tunit);
ss = mat2str(getisotopephotopeak(num2str(handles.isotope)));
ss(findstr(ss,' ')) = ',';
set(handles.edit_photopeak,'String',ss);
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function popupmenu_isotope_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------
function edit_measuredActivity_mci_Callback(hObject, eventdata, handles)
%-----------------------------------------------------------------------
mesactivitymci = str2double(get(hObject, 'String'));
if isnan(mesactivitymci)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.activitydata.mesactivitymci = mesactivitymci;
mesactivitymbq = mesactivitymci*37;
handles.activitydata.mesactivitymbq = mesactivitymbq;
set(handles.edit_measuredActivity_mci, 'String', num2str(mesactivitymci));
set(handles.edit_measuredActivity_mbq, 'String', num2str(mesactivitymbq));
guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function edit_measuredActivity_mci_CreateFcn(hObject, eventdata, handles)
%-----------------------------------------------------------------------
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------
function edit_measuredActivity_mbq_Callback(hObject, eventdata, handles)
%-----------------------------------------------------------------------
mesactivitymbq = str2double(get(hObject, 'String'));
if isnan(mesactivitymbq)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.activitydata.mesactivitymbq = mesactivitymbq;
mesactivitymci = mesactivitymbq/37;
handles.activitydata.mesactivitymci = mesactivitymci;
set(handles.edit_measuredActivity_mci, 'String', num2str(mesactivitymci));
set(handles.edit_measuredActivity_mbq, 'String', num2str(mesactivitymbq));
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function edit_measuredActivity_mbq_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%-----------------------------------------------------------------------
function edit_measuredTime_Callback(hObject, eventdata, handles)
%-----------------------------------------------------------------------
handles = updateEllapsedTime(handles);
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function edit_measuredTime_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------
function edit_calculationTime_Callback(hObject, eventdata, handles)
%-----------------------------------------------------------------------
% --- Executes during object creation, after setting all properties.
handles = updateEllapsedTime(handles);
guidata(hObject,handles);
%-----------------------------------------------------------------------
function edit_calculationTime_CreateFcn(hObject, eventdata, handles)
%-----------------------------------------------------------------------
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --------------------------------------------------------------------
function edit_calculatedActivity_mci_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'String') returns contents of edit_calculatedActivity_mci as text
%        str2double(get(hObject,'String')) returns contents of edit_calculatedActivity_mci as a double

% --------------------------------------------------------------------
% --- Executes during object creation, after setting all properties.
function edit_calculatedActivity_mci_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function edit_calculatedActivity_mbq_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function edit_calculatedActivity_mbq_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
% --- Executes on button press in pushbutton_calculate.
function pushbutton_calculate_Callback(hObject, eventdata, handles)
%Get the activity and isotope
activity = str2double(get(handles.edit_measuredActivity_mci,'String'));
if activity > 0
    cf = handles.isotopecorectionfactor;
    t12 = cf*str2double(get(handles.edit_halflife,'String'));
    measDate = get(handles.edit_measuredDate,'String');
    measDate = datestr(datenum(measDate,'mm:dd:yyyy'),1);
    measTime = get(handles.edit_measuredTime,'String');
    measTimeVec = datevec([measDate,' ', measTime]);
    
    calcDate = get(handles.edit_calculationDate,'String');
    calcDate = datestr(datenum(calcDate,'mm:dd:yyyy'),1);
    calcTime = get(handles.edit_calculationTime,'String');
    calcTimeVec = datevec([calcDate,' ', calcTime]);
    t = etime(calcTimeVec,measTimeVec);
    [S,days] = etimev(calcTimeVec,measTimeVec);
    set(handles.edit_ellapsedNumberofDays,'String',num2str(days));
    if t < 0
    set(handles.edit_ellapsedtime,'String',['-',S]);
    else
      set(handles.edit_ellapsedtime,'String',S);
    end
    % Calculate the activity
    DF   = exp(-0.6931*(t)/t12);
    Actmci = DF*activity;
    % display calculated activities
    set(handles.edit_calculatedActivity_mci,'String',num2str(Actmci));
    set(handles.edit_calculatedActivity_mbq,'String',num2str(37*Actmci));
end
% calculate decay factor and display
% --------------------------------------------------------------------
% --- Executes on button press in pushbutton_reset.
function pushbutton_reset_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
initialize_gui(gcbf, handles);

% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles)
if isfield(handles, 'metricdata') && ~isreset
    return;
end
set(handles.edit_measuredActivity_mci,'String','0');
set(handles.edit_measuredActivity_mbq,'String','0');
set(handles.edit_measuredTime,'String',datestr(now,'HH:MM:SS'));
set(handles.edit_calculationTime,'String',datestr(now,'HH:MM:SS'));
set(handles.edit_ellapsedtime,'String','00:00:00');
set(handles.edit_measuredDate,'String', datestr(now,'mm:dd:yyyy'));
set(handles.edit_calculationDate,'String',datestr(now,'mm:dd:yyyy'));
set(handles.edit_calculatedActivity_mci,'String','0');
set(handles.edit_calculatedActivity_mbq,'String','0');
set(handles.edit_ellapsedNumberofDays,'String','0');
set(handles.popupmenu_isotope,'Value',1);
handles.isotope = 'Tc-99m';
set(handles.edit_halflife,'String',getisotopehalflife1(handles.isotope));
ss = mat2str(getisotopephotopeak(num2str(handles.isotope)));
[t12,tunitnum]= getisotopehalflife1(num2str(handles.isotope));
[tunit,cf] = gethalflifeunit(tunitnum);
handles.isotopecorectionfactor = cf;
ss(findstr(ss,' ')) = ',';
set(handles.edit_photopeak,'String',ss);
% Update handles structure
guidata(handles.figure1, handles);
% --------------------------------------------------------------------
function edit_halflife_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function edit_halflife_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
% --- Executes on button press in pushbutton_quit.
function pushbutton_quit_Callback(hObject, eventdata, handles)
button = questdlg('Are you sure you want to quit?','Confirm Quit','Yes','No','No');
switch button
    case 'Yes'
        if isfield(handles,'figure1') & ishandle(handles.figure1),
            close(handles.figure1);
        end
    case 'No'
    case 'Cancel'
end
% --------------------------------------------------------------------
function edit_photopeak_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function edit_photopeak_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function edit_ellapsedtime_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties
function edit_ellapsedtime_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function edit_calculationDate_Callback(hObject, eventdata, handles)

handles = updateEllapsedTime(handles);
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
% --------------------------------------------------------------------
function edit_calculationDate_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function edit_measuredDate_Callback(hObject, eventdata, handles)
handles = updateEllapsedTime(handles);
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function edit_measuredDate_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function edit_decayMode_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function edit_decayMode_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function edit_ellapsedNumberofDays_Callback(hObject, eventdata, handles)
function edit_ellapsedNumberofDays_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function handles = updateEllapsedTime (handles)
measDate = get(handles.edit_measuredDate,'String');
measDate = datestr(datenum(measDate,'mm:dd:yyyy'),1);
measTime = get(handles.edit_measuredTime,'String');
measTimeVec = datevec([measDate,' ', measTime]);
calcDate = get(handles.edit_calculationDate,'String');
calcDate = datestr(datenum(calcDate,'mm:dd:yyyy'),1);
calcTime = get(handles.edit_calculationTime,'String');
calcTimeVec = datevec([calcDate,' ', calcTime]);
[S,days] = etimev(calcTimeVec,measTimeVec);
t = etime(calcTimeVec,measTimeVec);
set(handles.edit_ellapsedNumberofDays,'String',num2str(days));
if t < 0
    set(handles.edit_ellapsedtime,'String',['-',S]);
else
    set(handles.edit_ellapsedtime,'String',S);
end

% ---------------------------------------------------------------
% Calculates the ellapsed time
function [S,days] = etimev(t1,t0)
tneg = 0;
if t1 < 0
    tneg = 1; t1 = - t1;
end
if(exist('t1')&exist('t0')&length(t1)>2&length(t0)>2)
    t = etime(t1,t0);
    if(t<0) t=-t;end
elseif(length(t1)==1) t = t1; else t = 0;  end
days=floor(t/(24*60*60)); t=t-days*24*60*60;
hours=floor(t/(60*60)); t=t-hours*60*60; mins=floor(t/60);
t=floor(t-mins*60);
if tneg
    S = ['-' num2str(hours),':', num2str(mins),':', num2str(t)];
else
    S = [num2str(hours),':', num2str(mins),':', num2str(t)];
end



Contact us at files@mathworks.com