MATLAB: After dcm = double(dcm) setappdata will always give me 0.

getappdataguiguidematlab guisetappdata

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

set(handles.text5,'string','dcm2vol.m')
set(handles.text2,'string','PROCESSING IN PROGRESS. PLEASE WAIT')
pause(1)
din = 'C:\Users\ying0018\Documents\MATLAB\Original_DICOM';
dcm = dcm2vol(din)
assignin('base','din',din)
assignin('base','dcm',dcm)
setappdata(0,'pushbutton1',dcm);
set(handles.text2,'string','PROCESSING COMPLETED SUCCESSFULLY')
%*From pushbutton1, i can get the value for dcm which is -2084*
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dcm = getappdata(0,'pushbutton1');
MR = getappdata(0,'pushbutton2');
set(handles.text5,'string','Rightmaskdcm.m')
set(handles.text2,'string','PROCESSING IN PROGRESS. PLEASE WAIT')
pause(1)
dcm = double(dcm)
setappdata(0,'pushbutton4',dcm);
pause(1)
dcmmR = Rightmaskdcm(dcm,MR)
assignin('base','dcm',dcm)
assignin('base','dcmmR',dcmmR)
setappdata(0,'pushbutton4',dcmmR);
set(handles.text2,'string','PROCESSING COMPLETED SUCCESSFULLY')
assignin correctly returns the value of the new dcm after double which is -2084. However setappdata set the new dcm to 0. which does not make sense. In the workspace: dcm = 512x512x481 (int16) new dcm = 512x512x481 (double) why setappdata cannot capture the values of double dcm?

Best Answer

You have
setappdata(0,'pushbutton4',dcm);
and later
setappdata(0,'pushbutton4',dcmmR);
so you are overwriting the app data named 'pushbutton4'.
Perhaps what you want is
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

set(handles.text5,'string','dcm2vol.m')
set(handles.text2,'string','PROCESSING IN PROGRESS. PLEASE WAIT')
pause(1)
din = 'C:\Users\ying0018\Documents\MATLAB\Original_DICOM';
dcm = dcm2vol(din)
assignin('base','din',din)
assignin('base','dcm',dcm)
setappdata(hObject, 'dcm', dcm)
set(handles.text2,'string','PROCESSING COMPLETED SUCCESSFULLY')
%*From pushbutton1, i can get the value for dcm which is -2084*
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dcm = getappdata(handles.pushbutton1, 'dcm');
MR = getappdata(handles.'pushbutton2', 'MR');
set(handles.text5,'string','Rightmaskdcm.m')
set(handles.text2,'string','PROCESSING IN PROGRESS. PLEASE WAIT')
pause(1)
dcm = double(dcm)
setappdata(hObject, 'dcm', dcm);
pause(1)
dcmmR = Rightmaskdcm(dcm,MR)
assignin('base','dcm',dcm)
assignin('base','dcmmR',dcmmR)
setappdata(hObject, 'dcmmR', dcmmR);
set(handles.text2,'string','PROCESSING COMPLETED SUCCESSFULLY')
Related Question